当前位置:网站首页>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
边栏推荐
- Deploy LNMP automatically with saltstack
- English Translation Spanish - batch English Translation Spanish tools free of charge
- First blog
- Edge detection and connection of image segmentation realized by MATLAB
- In order to develop high-end photoresist, Jingrui Co., Ltd. invested 75million yuan to purchase SK Hynix ASML lithography machine
- shared_ PTR and make_ Use of shared
- 时间转日期的sql语句应该怎么写?
- My second blog - C language
- 个人博克系统登录点击图形验证码的集成与实现
- Thoroughly understand bit operations -- and (&), not (~), or (|), XOR (^)
猜你喜欢
MATLAB实现的图像分割之边缘检测和连接
时间转日期的sql语句应该怎么写?
Can China make a breakthrough in the future development of the meta universe and occupy the highland?
你知道雨的类型有几种?
NetCoreAPI操作Excel表格
Basic usage of docker
In the second half of 2022, the system integration project management engineer certification starts on August 20
English translation Arabic - batch English translation Arabic tools free of charge
数字图像理论知识(一)(个人浅析)
Android-第十三节03xUtils-数据库框架(增删改查)详解
随机推荐
数字滤波器设计——Matlab
冲刺金九银十丨熬夜半个月汇集大厂Android岗1600道面试真题
Deploy LNMP automatically with saltstack
利用STM32的HAL库驱动1.54寸 TFT屏(240*240 ST7789V)
Common modules of saltstack
JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver
Function fitting based on MATLAB
Know small and medium LAN WLAN
MySQL性能测试工具sysbench学习
Labelme(一)
Basic knowledge of communication network 01
[网络]跨区域网络的通信学习IPv4地址的分类和计算
China's first chip stamp released: built-in 120um ultra-thin NFC chip
editor.md中markdown编辑器的实现
Idea properties file display \u solution of not displaying Chinese
Leetcode day3 employees who exceed the manager's income
leetcode day3 查找重复的电子邮箱
软考高级考试中有五大证书,哪个更值得考?
[in depth study of 4g/5g/6g topics -44]: urllc-15 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -9-low delay technology -3-non slot scheduling mini
架构基本概念和架构本质