Why is %c used in C?

Total
0
Shares

According to K&R C section 1.6, a char is a type of integer. So why do we need %c. And why can’t we use %d for everything?


Solution

Because %d will print the numeric character code of the char:

printf("%d", 'a');

prints 97 (on an ASCII system), while

printf("%c", 'a');

prints a.

Source: StackOverflow.com

Leave a Reply

Your email address will not be published. Required fields are marked *