我想知道为什么我的 C 程序不打印任何信息。我是 100% 的编程新手,在过去的几周里,我已经能够在 Ruby 和 Python 中学习一些东西,但是我对 C 的东西一无所知。这是每个人首先学习的总基线简单程序:
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
所以我已经写好了,我保存为 hello.c。现在我 cd 到它所在的目录,然后我尝试
gcc hello.c
什么也没有发生 - 没有错误,什么都没有。如果我改写
gcc hello.c -o hello
一个新的可执行文件被写入我的目录,当我打开它时,它看起来像普通的命令行,并且写有“Hello World”,正如我第一次在终端中所期望的那样。
我也尝试让 hello.c 本身成为可执行文件,但是当我这样做时,我得到了
syntax error near unexpected token `('
`int main()'