当前位置:网站首页>Basic knowledge of C language
Basic knowledge of C language
2022-07-28 20:00:00 【Embedded Xiaobai aspires to be a boss】
- Constant
- Variable
- Type conversion
- Constant
During program operation , The amount whose value will not be changed
1.1 character constants
‘a’ ‘b’ ‘c’
1.2 integer constants
Binary system :0110
octal :066
Decimal system :24
Hexadecimal :0x33
Be careful : By default , The integer constant is A signed Of int type (long、longlong、short)
Unsigned int type :66U
Long integer :66L
Long integer without sign :66UL
1.3 Floating point constants
Decimal form :1.23 0.00001 100000( Floating point constants contain integer constants )
Exponential form :0.0001 (1e-4) 100000 (1e+5)
1.4 String constant
“hello” Several bytes
Be careful : String is based on ’\0’ As an end sign
1.5 Identity constant ( macro )
#define Macro name expression
Be careful :(1) Macro names are usually capitalized , Lowercase is fine , Because in order to distinguish from variables , So use capital
(2) There is no semicolon after the macro
Macros are simply replacements
Macro functions ( It has the characteristics of both functions and macros )
#define Function name ( Shape parameter ) The body of the function
Be careful : Macros are simply symbolic substitutions , The priority of operators will not be considered , So we need to give each shape (), The entire expression is also bracketed
2、 Variable
Definition : It means opening up space in memory
c Memory allocation diagram of language :
How to define a variable ?
Storage type data type Variable name ;
Storage type : Determines which partition of the opened space is in the memory
data type : Determines the size of memory space to be opened
Variable name : The name of the opened memory space
2.1 local variable
Defined in function body ( Any function body ) Internal variables
2.2 Global variables
Variables defined outside the function
2.3 Storage type
Storage type :auto、extern、static、register
auto: Decorated variables are stored in the stack , Only local variables can be modified
extern: Decorated variables are stored in the static area (.bss and .data Collectively referred to as static areas ), Only global variables can be modified
static: Decorated variables are stored in the static area , Both local and global variables can be modified
register: Decorated variables are stored in registers , Only local variables can be modified
summary :
- except static and register Modified local variables , There are stack areas for others
- Static area exists in global variables
- Static variables have static areas
2.4 initialization
initialization : Assign values to variables when defining variables
- int a = 10; // initialization
- int a;
a = 10; // assignment
summary :(1) The global variable is not initialized, and its value defaults to 0
(2) Local variables are not initialized, and their values default to random values
auto: Modify local variables , Store in stack area
register: Modify local variables , Stored in a register , It is recommended to store variables in registers , Can improve the running speed of the program , Whether it is finally stored in the register , Depends on the compiler , If there are no registers , There is a stack area
extern: Modify global variable , Store in static area
The program can consist of multiple .C The composition of the document , however A program can only have one main function
effect : Tell compiler , This global variable has been defined in other files
static: Decorated variables are stored in the static area , You can modify both local variables and global variables
- static Modify local variables , Prolongs the life cycle of local variables , If the local variable is not initialized , Its value is 0, If initialization is only assigned once
- static Modify global variable , Only in this document ( Limits the scope of global variables )
2.5 Lifecycle and scope
Life cycle
From when to open up space to when to release space
Scope
Scope of use
local variable :
Life cycle : Start with the definition , To module ( Curly braces ) end
Scope : In braces
static Modified local variables :
Life cycle : Start with the definition , By the end of the program
Scope : In braces
Global variables :
Life cycle : Start with the definition , By the end of the program
Scope : Whole procedure
static Decorated global variables :
Life cycle : Start with the definition , By the end of the program
Scope : In this document
3、 Data type conversion
3.1 Cast ( We turn by ourselves )
3.2 Implicit type conversion ( The compiler automatically transfers )
Horizontal arrow : Whether we have mixed operations or not , Are bound to be converted
Be careful :float When using, follow double To use the
Empathy :char、short Is in accordance with the int To use the
Vertical arrow : Only in the case of mixed operations , To switch
边栏推荐
- 软考中级(系统集成项目管理工程师)高频考点
- Business visualization - let your flowchart "run" (4. Actual business scenario test)
- NPM installing and uninstalling global packages
- Stories of Party members | Li qingai uses cartoons to drive farmers to increase income and become rich
- [network] communication across regional networks learn how routing tables work
- Deploy ZABBIX automatically with saltstack
- Data system of saltstack
- With the help of panel industry innovation, will FPGA become the best choice for TCON?
- [experience] some suggestions and experience on repairing electronic equipment
- 数字图像理论知识(一)(个人浅析)
猜你喜欢

High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation

Can China make a breakthrough in the future development of the meta universe and occupy the highland?

基于MATLAB的函数拟合

Netcoreapi operation excel table

JS preventdefault() keyboard input limit onmousewheel stoppropagation stop event propagation
![[wechat applet development] page navigation and parameter transmission](/img/10/76b6592fa9e71073831887c4fb6da9.png)
[wechat applet development] page navigation and parameter transmission

Servlet learning notes

利用STM32的HAL库驱动1.54寸 TFT屏(240*240 ST7789V)

How to write the SQL statement of time to date?

Basic knowledge of communication network 01
随机推荐
How openocd directly downloads programs to STM32 board through stlink (solved)
Common APIs in string
English Translation Spanish - batch English Translation Spanish tools free of charge
leetcode day3 超过经理收入的员工
leetcode day5 删除重复的电子邮箱
Why is there no log output in the telnet login interface?
There are five certificates in the soft examination advanced examination, which is more worth taking?
STC12C5A60S2 function description (STC12C5A60S2 is triggered by default)
11. Learn MySQL union operator
【微信小程序开发】页面导航与传参
Labelme (I)
[experience] some suggestions and experience on repairing electronic equipment
MIR专题征稿 | 常识知识与推理:表示、获取与应用 (10月31日截稿)
Cell review: single cell methods in human microbiome research
MySQL performance testing tool sysbench learning
Leetcode Day1 score ranking
[wechat applet development] page navigation and parameter transmission
软考高级考试中有五大证书,哪个更值得考?
leetcode day3 查找重复的电子邮箱
Edge detection and connection of image segmentation realized by MATLAB