当前位置:网站首页>You Li takes you to talk about C language 6 (common keywords)
You Li takes you to talk about C language 6 (common keywords)
2022-07-07 07:49:00 【Lu Youli】
C The language provides a wealth of keywords , And these keywords are predetermined , Users cannot create keywords themselves

Next I will introduce some keywords , Others that are not introduced will be mentioned later
keyword typedey
Can simplify a type , Redefinition
// take unsigned int Rename it to uint_32, therefore uint_32 It's also a type name
typedef unsigned int uint_32;
int main()
{
// Observe num1 and num2, The types of these two variables are the same
unsigned int num1 = 0;
uint_32 num2 = 0;
return 0; }
keyword static
stay C In language : static Is used to modify variables and functions
- Modify local variables - Called static local variables
- Modify global variable - Called static global variables
- Modify function - Called static function
keyword static – Modify local variables
```c
// Code 1
#include <stdio.h>
void test()
{
int a = 5;
// Stack area in memory
a++;
printf("%d ", a);
}
// They were destroyed when they went out
int main()
{
int i = 0;
for(i=0; i<10; i++)
{
test();
}
return 0; }
//6 6 6 6 6 6 6 6 6 6
// Code 2
#include <stdio.h>
void test()
{
//static Modify local variables
static int a = 5;
// Stored in the static area of memory
a++;
printf("%d ", a);
}
// It will not be destroyed after going out
int main()
{
int i = 0;
for(i=0; i<10; i++)
{
test();
}
return 0;
}
//6 - 15
Conclusion :
static When modifying local variables , The local variable becomes a static local variable, and the local variable goes out of the local range , Will not destroy , The next entry function still exists
Because :static Modified local variables are stored in the static area
static When modifying a local variable , What actually changes is the storage location of the variable , Originally, a local variable is placed in the stack area , By static After modification, it is placed in the static area .
As a result, the scope still exists , The life cycle doesn't end
keyword static – Modify global variable
static The function of modifier function :
A function originally has external link properties , But be static After modification , The external link attribute becomes the internal link attribute , At this time, this function can only be used inside its own source file , Other files cannot be used .
The scope becomes smaller
// Code 1
//add.c
int g_val = 2022;
//test.c
int main()
{
printf("%d\n", g_val);
return 0; }
// Code 2
//add.c
static int g_val = 2022;
//test.c
int main()
{
printf("%d\n", g_val);
return 0; }
边栏推荐
- Outsourcing for three years, abandoned
- 1142_ SiCp learning notes_ Functions and processes created by functions_ Linear recursion and iteration
- Flutter riverpod is comprehensively and deeply analyzed. Why is it officially recommended?
- Tianqing sends instructions to bypass the secondary verification
- ASEMI整流桥RS210参数,RS210规格,RS210封装
- Common method signatures and meanings of Iterable, collection and list
- pytest+allure+jenkins安装问题:pytest: error: unrecognized arguments: --alluredir
- 按键精灵脚本学习-关于天猫抢红包
- 今日现货白银操作建议
- 图解GPT3的工作原理
猜你喜欢

【经验分享】如何为visio扩展云服务图标

Operation suggestions for today's spot Silver

Outsourcing for four years, abandoned

After 95, Alibaba P7 published the payroll: it's really fragrant to make up this

Why should we understand the trend of spot gold?

SQL优化的魅力!从 30248s 到 0.001s

Leetcode-226. Invert Binary Tree

面试结束后,被面试官在朋友圈吐槽了......

2022-07-06:以下go语言代码是否会panic?A:会;B:不会。 package main import “C“ func main() { var ch chan struct

The metauniverse of the platofarm farm continues to expand, with Dao governance as the core
随机推荐
resource 创建包方式
探索Cassandra的去中心化分布式架构
[2022 actf] Web Topic recurrence
Make a bat file for cleaning system garbage
JSON introduction and JS parsing JSON
idea添加类注释模板和方法模板
Pytest + allure + Jenkins Environment - - achèvement du remplissage de la fosse
Route jump in wechat applet
After 95, the CV engineer posted the payroll and made up this. It's really fragrant
Iterable、Collection、List 的常见方法签名以及含义
@component(““)
gatk4中的interval是什么??
Info | webrtc M97 update
I failed in the postgraduate entrance examination and couldn't get into the big factory. I feel like it's over
leetcode:105. Constructing binary trees from preorder and inorder traversal sequences
Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
Detailed explanation of uboot image generation process of Hisilicon chip (hi3516dv300)
[experience sharing] how to expand the cloud service icon for Visio
[2022 ciscn] replay of preliminary web topics
nacos