You could see that the code also works with %d, %x, %u format specifiers.
Why it works without any warnings ?
Because you don't have warnings enabled in your CodeBlocks.
Go to settings -> compiler and check
Enable All Common Compiler Warnings [-Wall]
And now you get:
In function 'int main()':
warning: format '%c' expects argument of type 'int', but argument 2 has type 'const char*' [-Wformat=]|
Why it even works ?
With %c, $ is the output in CodeBlocks, X is the output in Visual Studio . So, that sounds like undefined behavior.
Wrong format specifiers in scanf (or) printf
Anyways if you want the first char this way only you could do this:
#include <stdio.h>
int main()
{
printf("%c", *"Hello\n"); // Not asked in Question but still :)
return 0;
}
It prints H by dereferencing the const pointer.