当前位置:网站首页>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
边栏推荐
- 浏览器渲染原理以及重排与重绘
- 外盘期货平台如何辨别正规安全?
- PHP talent recruitment system development source code recruitment website source code secondary development
- 阈值同态加密在隐私计算中的应用:解读
- npm安装
- 兰空图床苹果快捷指令
- Learnopongl notes (II) - Lighting
- How to uninstall MySQL cleanly
- Bs-xx-042 implementation of personnel management system based on SSM
- 齐宣王典故
猜你喜欢
Enter a command with the keyboard
Binary tree related OJ problems
File operation --i/o
ECU introduction
PHP talent recruitment system development source code recruitment website source code secondary development
Games101 notes (I)
【729. 我的日程安排錶 I】
【组队 PK 赛】本周任务已开启 | 答题挑战,夯实商品详情知识
Application of threshold homomorphic encryption in privacy Computing: Interpretation
Deep dive kotlin synergy (XXI): flow life cycle function
随机推荐
The difference between searching forward index and inverted index
【刷題篇】鹅廠文化衫問題
[61dctf]fm
解决CMakeList find_package找不到Qt5,找不到ECM
Excuse me, is the redis syntax used in DMS based on the commands of the redis community version of the cloud database
启牛商学院股票开户安全吗?靠谱吗?
Get ready for the pre-season card game MotoGP ignition champions!
Deeply cultivate 5g, and smart core continues to promote 5g applications
[first lecture on robot coordinate system]
npm安装
Cs231n notes (bottom) - applicable to 0 Foundation
Basic introduction to the control of the row component displaying its children in the horizontal array (tutorial includes source code)
深耕5G,芯讯通持续推动5G应用百花齐放
高数 | 旋转体体积计算方法汇总、二重积分计算旋转体体积
Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
Deep learning plus
阈值同态加密在隐私计算中的应用:解读
Timestamp strtotime the day before or after the date
Benji Banas membership pass holders' second quarter reward activities update list
Games101 notes (II)