Why does C’s printf format string have both %c and %s

cstring-formatting

Why does C's printf format string have both %c and %s?

I know that %c represents a single character and %s represents a null-terminated string of characters, but wouldn't the string representation alone be enough?

Best Answer

Probably to distinguish between null terminated string and a character. If they just had %s, then every single character must also be null terminated.

char c = 'a';

In the above case, c must be null terminated. This is my assumption though :)