Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么会printf("%c ", 2293552);打印0?
printf("%c ", 2293552);
0
ASCII 值是从 0 到 127 我知道这一定是一些循环的东西,但我想要一个清楚的解释。谢谢
数字2293552对应0x22ff30。当printf将其解释为 ASCII 时,它会忽略包含 的最后八位之外的所有位0x30,即'0'.
2293552
0x22ff30
printf
0x30
'0'
来自 C99 标准:
7.19.1.6.8 -- %c:如果不存在l长度修饰符,则将 int 参数转换为unsigned char,并写入结果字符。
%c
l
unsigned char
可能%c只使用参数的低位字节,即2293552 & 255 = 48 = '0'.
2293552 & 255 = 48 = '0'