当前位置:网站首页>Easy to understand C language keyword static
Easy to understand C language keyword static
2022-06-26 01:49:00 【So it is^^】
One :static Modify local variables
Unused static modification

use static After modification

From the code and results in Figure 1, we can see that Not by static modification The first 79 Line code , local variable i In the exit test Function time Will destroy data , Because the first 86 Row to 90 Code loop 10 Secondary entry test() function , Run out test Function is a local variable i Data destruction for , So the result is 10 Time i The value of is 2
As can be seen from Figure 2 , Every time you call test function , The use of i It's all left over from the last function call i, hold The data of local variables is saved , So the results i The value of is 2~11
You can see it here static Modified local variables It will not be destroyed even if it is out of its own scope , Equivalent to changing the life cycle of this local variable
Two :static Modify global variable


LNK In fact, it refers to link error
Figure 1 shows Global variables can be used in other files of the whole project , This is because global variables have external link attributes. As you can see in Figure 2 after static After modification , Global variables can only be used in source files , Other documents cannot be used , It gives us the feeling that the scope has become smaller
We can regard the whole project as a building , Different documents in a project are equivalent to different floors , The global variable is equivalent to a person on a certain floor of that building , In the absence of static When decorating, he can be in that building ( engineering ) Through the stairs ( link ) Can work in different floors ( file ), But once it's been static After modification , It is equivalent to dismantling the stairs ( Does not have external attributes ) A man can only be on his floor ( file ) Work in China
3、 ... and :static Modify function


whole static Decorating functions is similar to decorating global variables , It also makes the original function that can be called in other files of the whole project only in its source file ( That is, where the function is located .c perhaps .h file )
边栏推荐
- Cross validation -- a story that cannot be explained clearly
- Dataframe extracts data from a column and converts it into a list
- Eight principles of element positioning
- 胰蛋白酶的化学性质及应用
- makefile 中export set ENV 的区别和作用
- 浅谈接口测试(一)
- 23. histogram equalization
- 17.11 std:: atomic continuation, std:: async in-depth discussion
- Summary of knowledge points of catboost
- PTA class a simulated 11th bomb: 1124-1131
猜你喜欢

Postman斷言對應脚本的解釋

--SQL of urban cultivation manual -- Chapter 1 basic review

Show spirit chenzitong was invited to be the chief experience officer of the global finals of the sixth season perfect children's model

What happens from entering a web address in the browser's input box to seeing the contents of the web page?

CYCA少儿形体礼仪 乐清市培训成果考核圆满落幕

秀场精灵陈梓桐 受邀担任第六季完美童模全球总决赛首席体验官

Can bus transceiver principle

Abnova丨抗GBA单克隆抗体解决方案

GNN (graph neural network) introduction vernacular

元气少女王钰洁 受邀担任第六季完美童模全球总决赛代言人
随机推荐
17.11 std::atomic续谈、std::async深入谈
求n乘阶之和
PTA class a simulated ninth bullet: 1114-1117
CyCa children's physical etiquette Yueqing City training results assessment successfully concluded
CYCA少儿形体礼仪 乐清市培训成果考核圆满落幕
木瓜蛋白酶的特点及相关特异性介绍
APP测试与WEB测试的区别
通俗易懂C语言关键字static
胶原蛋白酶丨Worthington中英文说明书
--SQL of urban cultivation manual -- Chapter 1 basic review
蒟蒻初学单片机的一丢丢笔记
Assertion of postman interface test
Pixel6 unlock bootloader
NLP enhanced technology
Android system startup security
24. histogram calculation
Obtain WiFi password through computer (only connected WiFi)
xargs 的作用详解
Data arrangement of machinetranslation
2022 explosion proof electrical operation certificate examination question bank and simulation examination