当前位置:网站首页>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
边栏推荐
- 网上办理期货开户安全吗?网上会不会骗子比较多?感觉不太靠谱?
- 【729. 我的日程安排錶 I】
- dried food! Semi supervised pre training dialogue model space
- 【微信小程序】一文读懂小程序的生命周期和路由跳转
- Learnopongl notes (II) - Lighting
- Yarn common commands
- 高数 | 旋转体体积计算方法汇总、二重积分计算旋转体体积
- Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
- Jarvis OJ 简单网管协议
- 网站页面禁止复制内容 JS代码
猜你喜欢

Clear restore the scene 31 years ago, volcanic engine ultra clear repair beyond classic concert

Hiengine: comparable to the local cloud native memory database engine

Etcd 构建高可用Etcd集群

二叉树相关OJ题

Jarvis OJ shell traffic analysis

File operation --i/o

Jarvis OJ Telnet Protocol
![[brush title] goose factory shirt problem](/img/c8/44496c767a778101cf3982bd911933.png)
[brush title] goose factory shirt problem

【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试

How does win11 change icons for applications? Win11 method of changing icons for applications
随机推荐
What else do you not know about new map()
[729. My Schedule i]
JSON转MAP前后数据校验 -- 自定义UDF
PHP talent recruitment system development source code recruitment website source code secondary development
Do sqlserver have any requirements for database performance when doing CDC
Is it safe to open an account for digging wealth stocks? How is it safe to open a stock account?
What is ROM
[Jianzhi offer] 66 Build product array
Jarvis OJ Flag
Summary of PHP pseudo protocol of cisp-pte
How does win11 change icons for applications? Win11 method of changing icons for applications
【性能测试】jmeter+Grafana+influxdb部署实战
American chips are no longer proud, and Chinese chips have successfully won the first place in emerging fields
Machine learning compilation lesson 2: tensor program abstraction
深耕5G,芯讯通持续推动5G应用百花齐放
Twig数组合并的写法
[js] skill simplification if empty judgment
Detailed explanation of use scenarios and functions of polar coordinate sector diagram
养不起真猫,就用代码吸猫 -Unity 粒子实现画猫咪
Sentinel-流量防卫兵