Format specifier '% d'

The following code gives me output as 'd':

void main()
{

  short int a=5;

   printf("%d"+1,a);

   getch();

}

How does it work printf()?

+5
source share
3 answers

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", 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).

+6
source

printf("%d"+1,a);, ,   ( "% d" +1)

printf("%d+1",a);, printf("%d",a+1);

+3

, "% d", , , :

Item        Address        00   01   02   03
-----       -------        --   --   --   --
"%d"        0xfffbec00     '%'  'd'   0   ??

"% d" 0xfffbec00 (). "%d"+1, 1 ( 0xfffbec01), "d" printf.

"d" , printf as-is. a printf, .

+1
source

All Articles