当前位置:网站首页>Global variables & local variables
Global variables & local variables
2022-06-25 07:19:00 【Xinchen sea】
Scope :
Global variables : Its scope of action is “ The whole project ”, Just define... In one source file , It works on all source files . Of course , Other source files that do not contain global variable definitions need extern Keyword declares the global variable again
Static global variables : Use static Keyword modification , It also has global function , The difference from global variables is that if the program contains multiple files , Its scope is only in the defined file , Cannot work on other files , So even if two different source files define static global variables with the same name , They are also different variables
local variable : Just start at the defined position , To the right curly bracket that defines it , Exists only during function execution , After the execution of a call to the function , Variables are revoked , The memory it uses is also reclaimed
Static local variables : Local scope , It is initialized only once , It's been around since the first initialization until the end of the program , The difference with local variables is that after the function is executed, it still exists
Life span :
Global variables : As the process goes on
Static global variables : As the process goes on
local variable : From the beginning of the definition to the end of the function , The variable is undone after the function is called , Memory is recycled
Static local variables : As the process goes on ,static The lifetime of a modified local variable changes from a function to the entire process
Memory allocation :
Global variables : overall situation ( static state ) Storage area
Static global variables : overall situation ( static state ) Storage area
local variable : Store in a stack , Dynamically allocate storage units to variables only when the function is called
Static local variables : overall situation ( static state ) Storage area
Other :
overall situation ( static state ) Storage area : It is divided into DATA Paragraph and BSS paragraph .DATA paragraph ( Global initialization area ) Store initialized global variables and static variables ;BSS paragraph ( Global uninitialized area ) Store uninitialized global variables and static variables . Release automatically at the end of the program . among BBS Segments are automatically cleared by the system before the program is executed 0, So the uninitialized global variables and static variables have been changed to 0
Static variables are placed in the program's static data store ( The whole picture can be seen ) in , In this way, the original assignment can be kept at the next call . This is the difference between stack variable and heap variable
Variable usage static Tell the compiler , I am only visible in the range of variables . This is the difference between it and global variables
Changing a local variable to a static variable changes its storage mode, that is, its lifetime . Changing a global variable to a static variable changes its scope , It limits its use . therefore static The function of this specifier is different in different places ;
边栏推荐
- The process of making wooden barrels with 3DMAX software: a three-step process
- Too beautiful promise because too young
- Shandong finds clean energy that can be used by China for 3800 years? You should know the truth first
- Practice of hierarchical management based on kubesphere
- SQL query, if value is null then return 1 - SQL query, if value is null then return 1
- How to get the difference between two dates rounded to hours
- 活动报名|Apache Pulsar x KubeSphere 在线 Meetup 火热报名中
- Change the current count of auto increment values in MySQL- Changing the current count of an Auto Increment value in MySQL?
- 赚够钱回老家吗
- Drawing shp files using OpenGL
猜你喜欢
正版photoshop2022购买体验经历分享
Kube scheduler source code analysis (1) - initialization and startup analysis
【2022黑马程序员】SQL优化
The e-book "action guide for large organizations to further promote zero code application platform" was officially released!
Finally, when you open source the applet ~
网络是怎样连接的?
破万,我用了六年!
【xxl-job】池塘水绿风微暖,记得玉真初见面
我们不一样
I have used it for six years!
随机推荐
MCU IO explanation (pull-up pull-down quasi bidirectional input / output push-pull open drain)
Expression of fatherly love
Flexbox on ie11: stretching images for no reason- Flexbox on IE11: image stretched for no reason?
lotus v1.16.0-rc2 Calibration-net
Streamnational platform version 1.5 is released, integrating istio and supporting openshift deployment
Operate cnblogs metaweblog API
TEMPEST HDMI泄漏接收 1
Google extender address
shell 上下两行合并成一行
Kubernetes 集群中流量暴露的几种方案
Make enough money to go back home
正版photoshop2022购买体验经历分享
Efficient exploration | an application practice of ES geographical location query
想买股票去哪个证券公司开户更快更安全
破万,我用了六年!
alphassl通配符证书送一个月
SQL query, if value is null then return 1 - SQL query, if value is null then return 1
Reading sensor data with GPIO analog SPI interface
Shell command learning
单片机IO详解(上拉 下拉 准双向 输入 输出 推挽 开漏)