本博客讲解如何在Linux运行一个C语言程序
步骤:
1.编写C程序
新建一个hello.c文件
hello.c
代码如下:
#include <stdio.h>
int main()
{
/* 我的第一个 C 程序 */
printf("Hello, World! \n");
return 0;
}
2.编译C程序
$ gcc hello.c
注意:如果提示找不到gcc命令,则需要先安装gcc命令,方法自行百度
编译结果会多出一个a.out 文件
$ ls
a.out hello.c
如果需要指定编译输出的文件名,则编辑命令加上" -o 输出的文件名" 例如:
$ gcc hello.c -o hello.out
编译结果
$ ls
hello.c hello.out
3. 运行输出文件
语法: ./输出文件名
$ ./a.out
运行结果
$ ./a.out
Hello, World!
完成! enjoy it!