【C语言】在 Linux 终端编写、编译并运行 Hello world 程序

步骤

  1. 创建并打开 hello-world 文件夹
bash 复制代码
mkdir hello-world
cd hello-world
  1. 使用 vim 创建 main.c
bash 复制代码
vim main.c
  1. 写入代码并保存
c 复制代码
#include <stdio.h>

int main() {
    printf("Hello, world!\n");

    return 0;
}

#include <stdio.h> 是一个预处理命令,用于包含标准输入输出库文件。int main() 是主函数,程序从这里开始执行。printf("Hello, world!\n"); 用于在屏幕上打印"Hello, world!"。return 0; 语句用于退出程序。

  1. gcc 编译器将 main.c 文件编译为可执行文件 main
bash 复制代码
gcc main.c -o main

-o 选项用于指定输出文件的名称。

  1. 运行程序
bash 复制代码
./main

输出:

复制代码
Hello, world!
相关推荐
Y多了个想法1 天前
Linux驱动开发与Android驱动开发
android·linux·驱动开发
ctgu901 天前
PyQt5(八):ui设置为可以手动随意拉伸功能
开发语言·qt·ui
CVer儿1 天前
libtorch ITK 部署 nnUNetV2 模型
开发语言
asyxchenchong8881 天前
OpenLCA、GREET、R语言的生命周期评价方法、模型构建
开发语言·r语言
大锦终1 天前
【Linux】TCP协议
linux·运维·tcp/ip
没有梦想的咸鱼185-1037-16631 天前
【生命周期评价(LCA)】基于OpenLCA、GREET、R语言的生命周期评价方法、模型构建
开发语言·数据分析·r语言
czy87874751 天前
C语言实现策略模式
c语言·排序算法·策略模式
程序猿20231 天前
Python每日一练---第三天:删除有序数组中的重复项
开发语言·python
一只游鱼1 天前
Springboot+BannerBanner(启动横幅)
java·开发语言·数据库
一只游鱼1 天前
抖音上的用python实现激励弹窗
开发语言·python