c - What does %% do in printf? -
given following program in c,
#include <stdio.h> int main() { printf(" \"books %% or %% apparels\""); getchar(); return 0; } the program prints books % or % apparels, know significance of %%, because looks unnecessary.
% indicates format escape sequence used formatting variables passed printf().
so have escape print % character.
http://en.cppreference.com/w/c/io/fprintf
if replace %% %, this
#include <stdio.h> int main (int argc, char *argv[]) { printf(" \"books % or % apparels\""); return 0; } there 2 escape sequences printf():
"% o"[guesswork] not yields valid escape sequence
printf()disregards , print is."% a"printf()tryfloatempty parameter list , print "hexadecimal floating point, lowercase" (%a, see above webpage). due c calling convention (disclaimer: i'm not expert on this), garbage memory used , explains result.
actually compiler (gcc 4.4.3) issued warnings both:
$ gcc a.c a.c: in function ‘main’: a.c:3: warning: unknown conversion type character ‘o’ in format a.c:3: warning: few arguments format
Comments
Post a Comment