当前位置:网站首页>Embedded-c Language-1
Embedded-c Language-1
2022-07-05 17:03:00 【Orange peel does not stop school】
One 、 about C Description of language
You can understand it as : A language that enables people to communicate with computers , You write down the functions you want to achieve through the keyboard , Then there will be corresponding translation officers ( Compiler ) To help you translate , Let the computer understand what you think , Then the computer will mobilize its own resources to execute the commands you write .
1. Next, let's try to write !
On the way to writing, I will introduce some things involved in writing the project linux Common commands or shortcut keys .
ctrl+alt+t : Bring up the terminal ( You can also click , But try to master the keyboard )
mkdir -p /home/chenpi/csdn_c1 :( Note blank space )
mkdir The meaning of creating a file .
-p If mkdir Parent directory not found , This parameter will help create the parent directory first .
/home/chenpi/csdn_c1 The folder path you want to create .
vim hello.c : Use vim The editor writes the code , Save and exit after writing , This operation will create a .c The files are in this directory .
Get into vim after , Press i Enter edit mode , After writing the code ,
According to the first esc Exit to visual mode , At this time, you can only see , No more code changes ,
Then press shift+: Enter command line mode , Input wq, It means save and exit .
Save after exit , Input :
gcc helloworld.c ( compiler , It will generate a file that can be recognized by the computer )
gcc function : It is also a program , yes C The compiler of the program , Similar to the function of the translator , take C The source file of the program is translated into a file that the computer can recognize and understand .gcc Some grammars of are very common , Just study on Baidu by yourself .
ls -lh( You can use only ls, add -lh It can display information such as file size )
./a.out ( Run the program a.out , Ahead ./ Represents... In the current directory )
You can see the printed information .
2. Let's talk about defining variables :
int val;( Although I didn't count , But there will be a random number in it )
int var = 250;
int var1, var2, var3;
int var1 = 1, var2 = 2, var3 = 3;
All of the above , But pay attention to the following , Will report a mistake :
int 2var; //gcc Report errors , Because the first letter cannot be a number . It can only be letters or underscores , Case sensitive
Words with special meanings and functions , These words cannot be used casually
for example : int , return, void, main, include etc.
int int = 250; You cannot use keywords to get variable names
3. Let's talk about the data type of variables :
Data type function : Let the compiler gcc Calculate the memory space to be allocated by the variable in the future
12 The basic data types of class are as follows :
( Reading format : Keyword name / meaning / Allocated memory size / The range of numbers )
char Character type ( It is essentially a single byte integer ) 1 byte -128~127
unsigned char Nonnegative single byte integer 1 byte 0~255
short Double byte integer 2 byte -32768~32767
unsigned short Nonnegative double byte integer 2 byte 0~65535
int Four byte integer 4 byte -2^31~2^31-1
unsigned int Nonnegative four byte integer 4 byte 0~2^32-1
long Four byte integer 4 byte -2^31~2^31-1
unsigned long Nonnegative four byte integer 4 byte 0~2^32-1
long long Eight byte integers 8 byte -2^63~2^63-1
unsigned long long Nonnegative octet integer 8 byte 0~2^64-1
float Single-precision floating-point 4 byte A little
double Double precision floating point 8 byte A little
Be careful :
about 32 Bit system /64 Bit system , unsigned int All are 4 byte
about 32 Bit system ,unsigned long yes 4 byte
about 64 Bit system ,unsigned long yes 8 byte
You can also use keywords sizeof Be able to view the size of the allocated memory of the data type .
sizeof Keyword Syntax ∶ Memory size ( Unit is byte )= sizeof( Variable name or data type name )
for example ︰long long var = 1;
printf("%d \n",sizeof(var)); // You can print out the memory size used , Try it yourself .
4. Let's talk about integer data types
The keyword of integer data type is int
It can be used short perhaps unsigned short perhaps long perhaps unsigned long modification
therefore int Can represent 2 Byte or 4 byte
int Six forms of type :
form 1:short(int) use 2 The byte represents , A signed
short int a = 250; be equal to short a =250;
form 2:long(int) use 4 The byte represents , A signed
long int a = 250; be equal to long a = 250;
form 3:unsigned short(int) use 2 The byte represents , Unsigned
unsigned short int a = 250; be equal to unsigned short a = 250;
form 4:unsigned long(int) use 4 The byte represents , Unsigned
unsigned long int a = 250 ; be equal to unsigned long a = 250;
Integer constant :
100:gcc The compiler defaults to int type
100L:gcc The compiler regards it as long type
100LL:gcc The compiler regards it as long long type
100U:gcc The compiler regards it as unsigned int type
100UL:gcc The compiler regards it as unsigned long type
Floating point data types :float,double
1.23:gcc The compiler regards it as double type
1.23f:gcc The compiler regards it as float type
Data types and corresponding placeholders ( to printf Function USES )
data type Place holder
char %c , %hhd
unsigned char %c , %hhd
short %hd
unsigned short %hu
int %d
unsigned int %u
long %ld
unsigned long %lu
float %f perhaps %g // The former retains redundant 0, The latter is not reserved
double %lf perhaps %lg
边栏推荐
- 深耕5G,芯讯通持续推动5G应用百花齐放
- Learnopongl notes (I)
- Games101 notes (II)
- Practical example of propeller easydl: automatic scratch recognition of industrial parts
- Sentinel flow guard
- Do sqlserver have any requirements for database performance when doing CDC
- [Jianzhi offer] 61 Shunzi in playing cards
- 启牛商学院股票开户安全吗?靠谱吗?
- 【剑指 Offer】66. 构建乘积数组
- Jarvis OJ shell流量分析
猜你喜欢
采用药丸屏的iPhone14或引发中国消费者的热烈抢购
Jarvis OJ Flag
Jarvis OJ 远程登录协议
NPM installation
[61dctf]fm
PHP人才招聘系统开发 源代码 招聘网站源码二次开发
【729. 我的日程安排錶 I】
Win11 prompt: what if the software cannot be downloaded safely? Win11 cannot download software safely
Jarvis OJ shell traffic analysis
Benji Banas membership pass holders' second quarter reward activities update list
随机推荐
Keras crash Guide
Twig数组合并的写法
What is ROM
【机器人坐标系第一讲】
[61dctf]fm
The survey shows that the failure rate of traditional data security tools in the face of blackmail software attacks is as high as 60%
外盘期货平台如何辨别正规安全?
[Jianzhi offer] 66 Build product array
Jarvis OJ Flag
Jarvis OJ shell流量分析
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
[wechat applet] read the life cycle and route jump of the applet
什么是ROM
【729. 我的日程安排表 I】
【剑指 Offer】66. 构建乘积数组
[61dctf]fm
Summary of methods for finding intersection of ordered linked list sets
Games101 notes (I)
ECU简介
Can you help me see what the problem is? [ERROR] Could not execute SQL stateme