当前位置:网站首页>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; }
边栏推荐
- Leetcode-226. Invert Binary Tree
- 为什么要了解现货黄金走势?
- vus.SSR在asynData函数中请求数据的注意事项
- Outsourcing for four years, abandoned
- Asemi rectifier bridge rs210 parameters, rs210 specifications, rs210 package
- gslx680触摸屏驱动源码码分析(gslX680.c)
- buuctf misc USB
- 4、 High performance go language release optimization and landing practice youth training camp notes
- Simple example of ros2 planning system plansys2
- After the interview, the interviewer roast in the circle of friends
猜你喜欢
Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
@component(““)
The configuration that needs to be modified when switching between high and low versions of MySQL 5-8 (take aicode as an example here)
毕设-基于SSM大学生兼职平台系统
Mutual conversion between InputStream, int, shot, long and byte arrays
leetcode:105. Constructing binary trees from preorder and inorder traversal sequences
今日现货白银操作建议
@component(““)
The metauniverse of the platofarm farm continues to expand, with Dao governance as the core
A concurrent rule verification implementation
随机推荐
Kbu1510-asemi power supply special 15A rectifier bridge kbu1510
Wx is used in wechat applet Showtoast() for interface interaction
Determining the full type of a variable
JS get all date or time stamps between two time stamps
【经验分享】如何为visio扩展云服务图标
Make a bat file for cleaning system garbage
Jenkins remote build project timeout problem
php导出百万数据
Iterable、Collection、List 的常见方法签名以及含义
Outsourcing for four years, abandoned
Simple example of ros2 planning system plansys2
vus.SSR在asynData函数中请求数据的注意事项
[2022 ACTF]web题目复现
《动手学深度学习》(四) -- 卷积神经网络 CNN
PHP exports millions of data
毕设-基于SSM大学生兼职平台系统
[unity] several ideas about circular motion of objects
[OBS] win capture requires winrt
[P2P] local packet capturing
How can a 35 year old programmer build a technological moat?