首页 > 解决方案 > 尝试运行 C 程序时未显示输出

问题描述

当我尝试运行该程序时,我的终端不显示任何内容。

这是程序:

/* Print a message on the screen*/

#include <stdio.h>

int main()
{
    printf("Hello World.\n");
    return 0;
}

我做错什么了吗?

- 编辑 -

我的防病毒软件阻止了程序的执行。

标签: c

解决方案


在字符串末尾添加换行符(或使用puts):

/* Print out a message on the screen*/

#include <stdio.h>

main()
{
    printf("Hello World.\n");
    return 0;
}

通常编译器会将这个printf调用优化为puts("Hello, World.").

还建议声明mainint(use int main() ...)。


推荐阅读