当前位置:网站首页>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 ;
边栏推荐
- [learn shell programming easily]-5. Plan tasks
- 赚够钱回老家吗
- Blue Bridge Cup SCM module code (timer) (code + comments)
- Ppt template of small fresh open class education courseware
- 深入解析 Apache BookKeeper 系列:第三篇——读取原理
- From perceptron to transformer, a brief history of deep learning
- Understand ZBrush carving software and game modeling analysis
- Keil debug view variable prompt not in scope
- 【xxl-job】池塘水绿风微暖,记得玉真初见面
- MCU IO explanation (pull-up pull-down quasi bidirectional input / output push-pull open drain)
猜你喜欢

Love Terminator

Don't you know the evolution process and principle of such a comprehensive redis cluster model?

Keil debug view variable prompt not in scope

Direct select sort and quick sort

Ctfhub web information disclosure directory traversal

How is the network connected?

Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)

ES can finally find brother Wukong!

Kube scheduler source code analysis (1) - initialization and startup analysis

The king scheme in distributed locks - redisson
随机推荐
Simple and complete steps of vivado project
MCU IO explanation (pull-up pull-down quasi bidirectional input / output push-pull open drain)
TEMPEST HDMI泄漏接收 1
lotus v1.16.0-rc2 Calibration-net
How to store the directory / hierarchy / tree structure in the database- How to store directory / hierarchy / tree structure in the database?
Fastadmin cascade clear data
In depth analysis of Apache bookkeeper series: Part 3 - reading principle
From perceptron to transformer, a brief history of deep learning
【一起上水硕系列】Day 4
Torchserve pit avoidance Guide
Don't you know the evolution process and principle of such a comprehensive redis cluster model?
1W字|40 图|硬核 ES 实战
分布式锁中的王者方案 - Redisson
48 张图 | 手摸手教你微服务的性能监控、压测和调优
Drawing shp files using OpenGL
How is the network connected?
Blue Bridge Cup SCM module code (matrix key) (code + comments)
【C语言】给字符串增加分隔符
レ / leilei
Design a MySQL table for message queue to store message data