C语言入门

打开终端, 依次进行以下操作

  1. 新建hello.c文件,并写入代码
> alisa@localhost ~/c/c> touch hello.c
> alisa@localhost ~/c/c> vim hello.c

输入代码

#include <stdio.h>
 
int main()
{
    /* 我的第一个 C 程序 */
    printf("Hello, World! \n");
 
    return 0;
}

  1. 通过gcc编译,如果没有错误,命令提示符会跳到下一行,同时会生成一个a.out可执行文件
alisa@localhost ~/c/c> ls -al
total 8
drwxr-xr-x  3 alisa  staff   96 11 26 16:01 .
drwxr-xr-x  7 alisa  staff  224 11 26 15:56 ..
-rw-r--r--  1 alisa  staff  122 11 26 16:01 hello.c
alisa@localhost ~/c/c> gcc hello.c
alisa@localhost ~/c/c> ls -al
total 40
drwxr-xr-x  4 alisa  staff    128 11 26 16:02 .
drwxr-xr-x  7 alisa  staff    224 11 26 15:56 ..
-rwxr-xr-x  1 alisa  staff  12556 11 26 16:02 a.out
-rw-r--r--  1 alisa  staff    122 11 26 16:01 hello.c
  1. 最后,运行a.out文件,进行输出
>alisa@localhost ~/c/c> ./a.out
Hello, World!

请确保您的路径中已包含 gcc 编译器,并确保在包含源文件 hello.c 的目录中运行它。

注:如果是多个 c 代码的源码文件(test1.c 与 test2.c 是两个源代码文件。),编译方法如下:

$ gcc test1.c test2.c -o main.out
$ ./main.out

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值