#include <stdio.h>
int main()
{
printf("%c\n","\"\"\"\"\"");
}
This prints $ but not """""
Why "$" is printed when I try to run the C code above?
#include <stdio.h>
int main()
{
printf("%c\n","\"\"\"\"\"");
}
This prints $ but not """""
Why "$" is printed when I try to run the C code above?
You pass a string to printf
, not a char. Try '"'
What happens in your code is that the string is passed to printf
, but printf
expects a char. printf
now tries to interpret the address of this string as a char. In general, this is undefined behavior.
%c
is the format specifier for a single character; there is probably some conversion going on. You want %s
(for strings).
It actually prints some garbage, because your input is not a single character, is a sequence of characters. Try using %s instead of %c