【问题标题】:Why is there no output when I try to print a char?为什么我尝试打印字符时没有输出?
【发布时间】:2021-02-20 13:46:55
【问题描述】:

我有以下代码:

#include <stdio.h>

int main()
{
    char* var1 = "Z";
    char text = *var1 + 3;
    if(text > 'Z'){
        text = text - 'Z';
        printf("%c\n", text);
    } 
    return 0;
}

为什么运行时没有输出?如果我使用 %d 而不是 %c 打印,它可以工作并且打印“3”。

【问题讨论】:

  • char* var1 = "Z"; 必须是 const char* var1 = "Z";

标签: c pointers printf


【解决方案1】:

https://en.wikipedia.org/wiki/ASCII

因为text - 'Z' = 3 不是可打印字符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-28
    • 2020-03-15
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    相关资源
    最近更新 更多