The following code gives me output as 'd':
void main() { short int a=5; printf("%d"+1,a); getch(); }
How does it work printf()?
printf()
printfthe format specifier does not "see" because you pass a pointer to "%d"plus one. This is equivalent to going on your "d"own:
printf
"%d"
"d"
printf("d", a);
prints dand ignores a. This is not the case printf; pointer arithmetic works with all pointers char, including pointers derived from string literals (i.e. double character quotes).
d
a
char
printf("%d"+1,a);, , ( "% d" +1)
printf("%d"+1,a);
printf("%d+1",a);, printf("%d",a+1);
printf("%d+1",a);
printf("%d",a+1);
, "% d", , , :
Item Address 00 01 02 03 ----- ------- -- -- -- -- "%d" 0xfffbec00 '%' 'd' 0 ??
"% d" 0xfffbec00 (). "%d"+1, 1 ( 0xfffbec01), "d" printf.
"%d"+1
"d" , printf as-is. a printf, .