-
Printf buffer
Dear all, look at this:
printf("℅d",3,3);
printf("%d %d");
It prints 333
The first 3 is printed as expected, the second goes to the buffer and is printed instead of the second "%d"
But the third "%d" not referred to any number or buffered data , it prints the third 3, where is this coming from?
Thx
-
You're looking at the effects of undefined behaviour. The format specifiers must correspond with the arguments, for both printf calls.
-
As @laserlight says: undefined behavior.
Tip: If you are using glibc and want to use only one argument, you can do, for example:
Code:
printf( "%1$d -> 0x%1$02x", 3 );
Will print: