当前位置:网站首页>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 .
边栏推荐
- I include of spring and Autumn
- Coding devsecops helps financial enterprises run out of digital acceleration
- JMeter performance test: serveragent resource monitoring
- How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
- JS knowledge points-01
- F. Min cost string problem solving Report
- Object. defineProperty() - VS - new Proxy()
- F. Weights assignment for tree edges problem solving Report
- I want to inquire about how to ensure data consistency when a MySQL transaction updates multiple tables?
- I spring web upload
猜你喜欢
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
Creation and optimization of MySQL index
CSRF, XSS science popularization and defense
Coding devsecops helps financial enterprises run out of digital acceleration
MySQL----函数
lv_font_conv离线转换
SQL Server learning notes
How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
超越PaLM!北大碩士提出DiVeRSe,全面刷新NLP推理排行榜
机器学习笔记 - 灰狼优化
随机推荐
Common redis data types and application scenarios
MySQL----函数
Go learning ----- relevant knowledge of JWT
如何将 DevSecOps 引入企业?
Easyocr character recognition
I spring and autumn blasting-1
ICML 2022 | explore the best architecture and training method of language model
How to introduce devsecops into enterprises?
GPS original coordinates to Baidu map coordinates (pure C code)
D-snow halo solution
Bubble sort, insert sort
Example of lvgl display picture
qt creater断点调试程序详解
JMeter performance test: serveragent resource monitoring
1330:【例8.3】最少步数
JS knowledge points-01
可转债打新在哪里操作开户是更安全可靠的呢
Common MySQL interview questions (1) (written MySQL interview questions)
JS topic - console log()
R 熵权法计算权重及综合得分