Why is %c used in C?

前端 未结 6 1080
误落风尘
误落风尘 2021-01-05 10:55

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?

6条回答
  •  借酒劲吻你
    2021-01-05 11:11

    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.

提交回复
热议问题