Using an incorrect format specifier in the first argument to
printf invokes undefined behavior.
For example, the code below invokes undefined behavior:
long z = 'B'; printf("%c\n", z);
Here is another example
Above line of code is undefined behavior.
%f expects double. However 0 is of type
Note that your compiler usually can help you avoid cases like these, if you turn on the proper flags during compiling (
gcc). From the last example:
warning: format specifies type 'double' but the argument has type 'int' [-Wformat] printf("%f\n",0); ~~ ^ %d