当前位置:网站首页>The basis of C language grammar -- learning of local variables and storage categories, global variables and storage categories, and macro definitions
The basis of C language grammar -- learning of local variables and storage categories, global variables and storage categories, and macro definitions
2022-06-26 09:50:00 【Tanzanian auduvi Canyon expert】
Macro definition
// Macro definitions are just doubles , You don't need parentheses , Generally, the name is in capital letters
#define B(c) c*c
main(){
int m=5, n=8,k;
k=10*B(m+n); // yes 10*5+8*5+8=98 instead of 10*(5+8
)*(5+8)
printf("%d",k);
}
local variable
Defining variables may have 3 In this case :
(1) Define at the beginning of a function ;
(2) Define in a compound statement within a function ;
(3) Define outside the function .
Specific definition :
Variables defined within a function are valid only within the scope of the function , In other words, they can only be referenced in this function , These variables cannot be used outside of this function . Variables defined in a compound statement are valid only within the scope of the compound statement , They can only be referenced within this compound statement . These variables cannot be used outside the compound statement , These are called “ local variable ”.

Global variables
Definition :
The variables defined outside the function belong to external variables and also become global variables or global variables .
Global variables can be used by other functions in this document .
Its valid range is from the beginning of definition to the end of this source file .

Global variables have the same name as local variables 
The storage category of the local variable
1. Automatic variable
use auto Keyword declaration .
Or not auto, The default is auto store category .
The formal parameters and local variables in the function belong to this type . When the function is called , The system automatically allocates storage space to variables , This space is automatically freed at the end of the call .
int f(int a){
auto int b,c=3;
}
2. Static local variables
use static Keyword declaration .
We hope that the local variables in the function will not disappear after the end, but continue to retain the original value , That is, the occupied storage space remains unchanged , On the next call , You can continue to use its value , At this time, you need to use local static variables to declare .
3. Register variables
use register Keyword declaration .
Generally speaking, static variables 、 Dynamic variables are stored in memory , Use the value of a variable every time , Will be taken out of memory first , Send to calculator , If you need to save , In memory . Too many times ,10000 Secondary cycle ? This process is too time-consuming , To improve efficiency , OK, these variables are stored in cpu In the register of , Get... Directly from the register when necessary , Because register reading is much faster than memory reading , So these variables are called register variables .
Such as :
register int a;

Storage category of global variables :
Global variables are stored in static storage , Its life cycle is fixed , Exist in the whole program running . But its effect depends on different storage categories . Such as the following situations
Declared as an external variable use extern keyword .
Declared available for inclusion in this document use static keyword
1. Expand the scope of external variables inside a file
2. Extend the scope of external variables to other files
3. Limit the action of external variables to this document



边栏推荐
- Redis notes (14) - persistence and data recovery (data persistence RDB and AOF, data recovery, mixed persistence)
- Solve Django's if Version (1, 3, 3): raise improverlyconfigured ('mysqlclient 1.3.3 or new is required
- SQL modification of table structure
- The first problem troubleshooting process of re disk
- LeetCode 基本计算器 224. 227. follow up 394
- Wechat official account reported error 10003
- How to correctly open the USB debugging and complete log functions of Huawei mobile phones?
- My creation anniversary
- Logview Pro can be used if the log is too large
- LeetCode 剑指 Offer II 091.粉刷房子 - 原地修改
猜你喜欢

Learning to Generalize Unseen Domains via Memory-based Multi-Source Meta-Learning for Person Re-ID

Redis notes (13) - scan and keys search for specific prefix key fields (command format, usage examples, locating large keys)

力扣------从数组中移除最大值和最小值

2021-11-29 quintic polynomial of trajectory planning

GAN Inversion: A Survey

逻辑英语结构【重点】

【CVPR 2021】Unsupervised Multi-Source Domain Adaptation for Person Re-Identification (UMSDA)

Logview Pro can be used if the log is too large

【CVPR 2021】DatasetGAN: Efficient Labeled Data Factory with Minimal Human Effort

CVPR:Refining Pseudo Labels with Clustering Consensus over Generations for Unsupervised Object Re-ID
随机推荐
Badge collection 6:api\_ Use of level
logback
力扣------从数组中移除最大值和最小值
同花顺炒股软件安全性怎样?在同花顺怎么开户
MapReduce&Yarn理论
PHP extracts TXT text to store the domain name in JSON data
install ompl.sh
The third-party extension package of thinkphp6.0 supports uploading to Alibaba cloud and qiniu cloud
install ompl. sh
QPM suspended window setting information
进入页面输入框自动获取焦点
自动化测试——pytest框架介绍及示例
pcl install
Redis notes (16) - info instructions and command line tools (view memory, status, number of client connections, monitoring server, scan large keys, sampling server, execute batch commands, etc.)
Detailed explanation of the network security competition questions (2) of the 2021 national vocational college skills competition (secondary vocational group)
Badge series 5: use of codecov
LeetCode 958. 二叉树的完全性校验
Several connection query methods of SQL (internal connection, external connection, full connection and joint query)
Flutter's brain map notes are easy to find and search!
Deep learning (tentsorflow2. version) three good student performance problems (1)