当前位置:网站首页>Advanced level of static and extern
Advanced level of static and extern
2022-07-05 15:26:00 【Houli crab 670】
First of all, it is only within the scope of my knowledge , If it is incomplete or wrong , Welcome to point out thank you .
extern
extern Is used to declare external symbols ( In other projects )
Such as : In the same source file , I defined a global variable in a project , If you want to use it in another project , So you need extern Modify the , Pictured :
Of course, modifying functions is the same way , Pictured :
I believe you can understand at a glance , No explanation , If I don't know, I'll send a private message ok
static
There are three ways to use it , Here we will elaborate one by one
Before talking about these three methods of use , Let's start with something else ( I don't know what to call )
It is divided into these areas in the memory of the computer ( Of course, there are more than these ), The stack area will be destroyed after the life cycle , The life cycle of the static area is consistent with that of the program , Only the program ends , The life cycle of the static area will come to an end , such as :
According to the principle that , It should output "234567891011" Of , But only 10 individual 2, The reason is because a Stored in the stack , After using it once ,a Your data will not be saved , Destroy after running , So every output print() When , It's all about letting a=1 Start calculating , So there is the above result . The following will say how to solve this problem .
Modify local variables
Like the code diagram above , If you put a Put it in the static area a Data will not be destroyed , Pictured 
such , Only static Modifying variables a Just ,a It is put into the static area , So the data is preserved , The above results are output .
therefore , If you want local variables not to be destroyed, you can use static modification .
Modify global variable
Before I talk about it , Global variables are those with external link properties , Generally speaking, it can be used extern Statement to use .
Just like this. 
But if you use static Embellished words , It will put the global variables into the static area ( Look at the picture above ) So that it no longer has external link properties ( Directly above )
Use static It will be like this ,“ An unresolved external instruction ”, That is because it is put into the static area .
When you don't want others to use this variable ( function ) Or for other purposes , You can use static To modify global variables .
Modify function
Like global variables, they all have external link attributes , If you are static After modification, there are only internal link attributes , Similarly, it cannot be used in other projects of the same source file . Such as :
This is not added static Of 
This is a plus static Of 

And... Will appear after adding static Modify global variables , The usage is similar to that of global variables .
That's right static and extern Understanding of usage .
边栏推荐
- Cartoon: programmers don't repair computers!
- I collect multiple Oracle tables at the same time. After collecting for a while, I will report that Oracle's OGA memory is exceeded. Have you encountered it?
- Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
- Reconnaissance des caractères easycr
- Bugku's Ping
- 【jvm】运算指令
- mapper. Comments in XML files
- 社区团购撤城“后遗症”
- Au - delà du PARM! La maîtrise de l'Université de Pékin propose diverse pour actualiser complètement le classement du raisonnement du NLP
- The difference between abstract classes and interfaces in PHP (PHP interview theory question)
猜你喜欢

Reasons and solutions for redis cache penetration and cache avalanche

NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读

Redis' transaction mechanism

Common PHP interview questions (1) (written PHP interview questions)

Bugku telnet

Nine hours, nine people, nine doors problem solving Report
![1330: [example 8.3] minimum steps](/img/69/9cb13ac4f47979b498fa2254894ed1.gif)
1330: [example 8.3] minimum steps

MySQL 巨坑:update 更新慎用影响行数做判断!!!

Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking

Thymeleaf uses background custom tool classes to process text
随机推荐
Leetcode: Shortest Word Distance II
I collect multiple Oracle tables at the same time. After collecting for a while, I will report that Oracle's OGA memory is exceeded. Have you encountered it?
Ecotone technology has passed ISO27001 and iso21434 safety management system certification
OSI 七层模型
lv_ font_ Conv offline conversion
sql server学习笔记
Optional parameters in the for loop
Leetcode: Shortest Word Distance II
华为哈勃化身硬科技IPO收割机
Definition of episodic and batch
漫画:程序员不是修电脑的!
Want to ask the big guy, is there any synchronization from Tencent cloud Mysql to other places? Binlog saved by Tencent cloud MySQL on cos
JS bright blind your eyes date selector
Example of lvgl display picture
Creation and use of thymeleaf template
MySQL之CRUD
Stm32+bh1750 photosensitive sensor obtains light intensity
Select sort and bubble sort
DVWA range clearance tutorial
How to introduce devsecops into enterprises?