What happens when I use the wrong format specifier?

后端 未结 2 1707
小蘑菇
小蘑菇 2020-11-22 02:03

Just wondering what happens when I use the wrong format specifier in C?

For example:

x = \'A\';
printf(\"%c\\n\", x);
printf(\"%d\\n\", x);

x = 65;
         


        
2条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 02:39

    since x is A, the first print f will print: 'A'.

    The second will print the ascii value of A (look it up).

    The 3rd one will print the ascii character for 65 (I think this is A or a, but its a letter).

    The fourth one will print 65.

    The 5th one will print 128.

提交回复
热议问题