我有以下代码.
int ant = 10;
char converter = ant;
printf("This is where the char prints: %c", converter);
Run Code Online (Sandbox Code Playgroud)
为什么控制台仅在运行时打印出来:
This is where the char prints:
Run Code Online (Sandbox Code Playgroud)
为什么会这样?是否仍然可以使用%c并打印出值?我知道将%c更改为%d将允许我查看结果,但我想知道原因.
您正在打印由数字10 编码的字符:格式说明符%c用于输出字符,而不是它们的数值.
在ASCII中(很可能是使用的编码),那是\n; 换行符.你的终端可能能够处理它,你会在输出中看到一个额外的行.
如果要打印数值converter,则仅使用%d格式说明符(char类型被隐式转换int为调用站点的类型).
| 归档时间: |
|
| 查看次数: |
65 次 |
| 最近记录: |