当前位置:网站首页>Storage category
Storage category
2022-07-29 05:28:00 【Ryan fitter】
Storage class
1. Scope
Scope describes the area in the program where identifiers can be accessed . There are mainly : Block action area 、 Function scope 、 Function prototype scope 、 File scope .
2. link
C The variables are 3 Link properties : External links 、 internal link 、 No links . Where block scope 、 Function scope 、 Function prototype scope variables are all unlinked variables .
3. Storage period
Scopes and links describe the visibility of identifiers . A storage period describes the lifetime of an object accessed through these identifiers .C Yes 4 Seed storage period : Static storage period 、 Thread storage period 、 Automatic storage period 、 Dynamically allocate storage periods .
4.5 Storage categories
Storage class | Storage period | Scope | link | Declaration method |
---|---|---|---|---|
Automatically | Automatically | block | nothing | block |
register | Automatically | block | nothing | block , Use keywords register |
Static external links | static state | file | external | Out of all functions |
Static internal links | static state | file | Inside | Out of all functions , Use keywords static |
Static no link | static state | block | nothing | block , Use keywords static |
// Variables in blocks
#include <stdio.h>
int main(void)
{
int x = 30;// The original x
printf("x in outer block :%d at %p\n", x, &x);
{
int x = 77;
printf("x in inner block:%d at %p\n", x, &x);
}
printf("x in outer block :%d at %p\n", x, &x);
while (x++ < 33)// original x
{
int x = 100;// new x, Hide the original x
x++;
printf("x in while loop:%d at %p\n", x, &x);
}
printf("x in outer block :%d at %p\n", x, &x);
return 0;
}
Program output :
x in outer block :30 at 000000000061fe08
x in inner block:77 at 000000000061fe0c
x in outer block :30 at 000000000061fe08
x in while loop:101 at 000000000061fe0c
x in while loop:101 at 000000000061fe0c
x in while loop:101 at 000000000061fe0c
x in outer block :34 at 000000000061fe08
The above program shows the function of variables in different blocks to “{}” As a boundary .
5. Storage category specifier
keyword | explain |
---|---|
typedef | It has nothing to do with any memory , In the vast majority of cases , You cannot use more than one storage category specifier in a declaration , Therefore, you cannot use multiple storage category specifiers as typedef Part of . |
auto | Indicates that the variable is an automatic storage period , Can only be used in block scoped variable declarations . |
register | Variables for block scope only , Categorize variables into register storage categories , Request the fastest access to the variable , It also protects the address of the variable from being obtained . |
static | It indicates that the created object has a static storage period , Creating objects when loading programs , When the program ends, the object disappears . Block scoped static variables have no links ; File scope static variables have internal links . |
extern | Indicates that the declared variable is defined elsewhere . If included extern The declaration of has a file scope , Then the referenced variable must have an external link . If included extern The declaration of has a block scope , The referenced variable may have external or internal links , Depends on the defining declaration of variables . |
边栏推荐
- [event preview] cloud development, efficient and intelligent - the second Alibaba cloud ECS cloudbuild developer competition is about to start
- One dimensional array exercise
- Live broadcast preview | how to save 30% labor cost and shorten 80% trademark processing cycle?
- With frequent data leakage and deletion events, how should enterprises build a security defense line?
- 时间复杂度和空间复杂度
- 【C语言系列】— 字符串+部分转义字符详解+注释小技巧
- Allocate memory: malloc() and free()
- 数据泄漏、删除事件频发,企业应如何构建安全防线?
- Complete ecological map of R & D Efficiency & selection of Devops tools
- Container security open source detection tool - veinmind (mirror backdoor, malicious samples, sensitive information, weak password, etc.)
猜你喜欢
Alibaba cloud Zhang Xintao: heterogeneous computing provides surging power for the digital economy
OCCT学习002-----环境搭建
R & D efficiency | analysis of kubernetes' core technology and Devops' landing experience
预约中,2022京东云产业融合新品发布会线上开启
Come on! See how Clickhouse, which has risen 16 places a year, can be implemented in jd.com
携手数字人、数字空间、XR平台,阿里云与伙伴共同建设“新视界”
APP常用跨端技术栈深入分析
【活动预告】云上数字工厂与中小企业数字化转型创新论坛
NVIDIA Zhou Xijian: the last mile from design to digital marketing
QML control: combobox
随机推荐
Unity3d - the object is too far away to see
Helm chart for Kubernetes
AiTalk创始人梁宇淇:镜像连接虚拟与现实的纽带
webgl1.0下texture2D和texture2DProj区别
In depth analysis of common cross end technology stacks of app
C语言文件操作
浅谈范式
365天挑战LeetCode1000题——Day 036 二叉树剪枝 + 子数组和排序后的区间和 + 删除最短的子数组使剩余数组有序
Container security open source detection tool - veinmind (mirror backdoor, malicious samples, sensitive information, weak password, etc.)
Vs code的安装步骤及环境配置
Occt learning 002 - environment construction
京东云分布式链路追踪在金融场景的最佳实践
直播预告|如何节省30%人工成本,缩短80%商标办理周期?
力扣994:腐烂的橘子(BFS)
365 day challenge leetcode 1000 questions - day 037 elements and the maximum side length of squares less than or equal to the threshold + the number of subsequences that meet the conditions
More than 200 ISVs have settled in! The first anniversary of Alibaba cloud computing nest
第一周总结
OCCT学习001-----简介
携手数字人、数字空间、XR平台,阿里云与伙伴共同建设“新视界”
适创科技以云仿真平台,支持“中国智造”升级