当前位置:网站首页>C language tutorial (1) - preparation
C language tutorial (1) - preparation
2022-07-31 05:45:00 【Why are so many names taken?】
To start learning C language, you generally need to prepare:
- linux virtual machine download virtual machine
- gcc compiler (usually comes with linux)
As for how to install a virtual machine Baidu Yiyi I won’t say too much here.
So, how do you use a virtual machine?This requires some commands.
Right-click on the desktop, click open the terminal, you can enter commands in this interface.
Here are a few basic commands:
- mkdir + directory name create directory
- rm + filename delete file
- ls list files
- cp + file to copy + file after copy copy file
- ...
The basic usage of these commands can be obtained with the man command.
such as man mkdir
If you want to write c code, you can use the vi editor.Note that the c code ends with .c
vi + filename write file
vi has three modes:
- Command Mode
- Edit Mode
- Last line mode
The command mode is entered at the beginning, and no code can be written.At this point, click the "i" key to enter edit mode.In edit mode, you can write code.
Enter the following code in edit mode:
#includeint main(void){printf("Hello World");return 0;}
For the explanation of this code, we will gradually understand it later.in here
int main(void){return 0;}
It is often a framework for C code.
I believe everyone has experienced the pain of losing files without saving.So, how do we save the code we write?
First, we need to hit the Esc key to switch from edit mode to command mode.Then, click the ":" key to switch from command mode to last line mode.In the last line mode, enter wq to save and exit.
- w: save
- q: quit without saving
So, how to run this program?
After exiting vi, we are back where we entered the command before.In it, enter
gcc + filename
At this time, gcc will preprocess the c code (source file) we wrote (will be discussed later) and compile it to generate an executable file, the default is "a.out", to run the executable file, you need to input: ./+ filename.Running our "a.out", we can type
./a.out
Can I change the name of the executable to b.out?
The first method:
mv a.out b.out
What is mv?Enter the following command to view.
man mv
The second method, when generating the executable file, enter
gcc filename -o b.out
In this way, b.out can be directly generated as an executable file.
In addition, since man comes out in baby language, so Baidu translation
边栏推荐
猜你喜欢
随机推荐
数据集划分以及交叉验证法
Distributed transaction processing solution big PK!
tf.keras.utils.pad_sequences()
【C语言3个基本结构详解——顺序、选择、循环】
gin框架学习-Casbin入门指南(ACL、RBAC、域内RBAC模型)
数据库上机实验1 数据库定义语言
Proteus 8 Professional安装教程
Redis:安装使用
03 【数据代理 事件处理】
剑指offer基础版 ----第31天
02 【el和data的两种写法 MVVM模型】
C语言实验五 循环结构程序设计(二)
Oracle数据库中的“limit”查询
The interviewer asked me how to divide the database and the table?Fortunately, I summed up a set of eight-part essays
C语言教程(二)-printf及c自带的数据类型
详解扫雷游戏(C语言)
第7章 网络层第3次练习题答案(第三版)
Kubernetes certificate validity period modification
Interviewer, don't ask me to shake hands three times and wave four times again
gin框架学习-Casbin进阶之策略管理API使用方法