I tried the below c program & I expected to get compile time error, but why compiler isn't giving any error?
Your program will compile fine, as
printf() is a variadic function and the matching check of the number of format specifiers with supplied argument is not performed by default.
At runtime, your program exhibits undefined behaviour, as there in no argument supplied which has to be printed using the supplied format specifier.
As per chapter 188.8.131.52,
c99 standard, (from
If there are insufficient arguments for the format, the behavior is undefined.
If you compile using
-Wformat flag in
gcc, your compiler will produce the warning for the mismatch.