The first helloworldc language program in ubuntu


Preface

Use vi to write a simple C program that displays "Hello, World!", compile it with gcc and observe the compiled result

1. Basic tools used

  • vi: vi as the default editor for linux/unix
  • gcc: gcc as the most authoritative compiler of the C language

Second, the steps

1. First, use vi to write a C language program file, and enter the command line: vi text.c to create a file named "text.c"

Insert picture description here
The text.c code is as follows:

#include <stdio.h>
int main()
{
    
    
    printf("hello world!");
    return 0;
}

输入完成后按键盘上Esc退出输入模式,输入:wq将缓冲区内的资料写入磁盘中,并离开vi

At this time, the compilation of the text.c file cannot be completed. When using gcc,'gcc' not found, but can be installed with: sudo apt install gcc.
Open a new command window and enter sudo apt install gcc and wait for the download to complete

2. Compiled successfully

Insert picture description here
After successful compilation, a new a.out file will be generated.

Insert picture description here
Enter ./a.out and output hello world!

Guess you like

Origin blog.csdn.net/qq_44165430/article/details/109430319