当前位置:网站首页>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; }
边栏推荐
- Deep learning Flower Book + machine learning watermelon book electronic version I found
- 在线直播系统源码,使用ValueAnimator实现view放大缩小动画效果
- Invalid table alias or column reference`xxx`
- [webrtc] m98 Screen and Window Collection
- 【经验分享】如何为visio扩展云服务图标
- pytest+allure+jenkins环境--填坑完毕
- Zhilian + AV, AITO asked M7 to do more than ideal one
- leanote私有云笔记搭建
- [2022 ACTF]web题目复现
- buuctf misc USB
猜你喜欢
misc ez_ usb
Mysql高低版本切换需要修改的配置5-8(此处以aicode为例)
[mathematical notes] radian
PHP exports millions of data
About some details of final, I have something to say - learn about final CSDN creation clock out from the memory model
Technology cloud report: from robot to Cobot, human-computer integration is creating an era
Asemi rectifier bridge rs210 parameters, rs210 specifications, rs210 package
知识点滴 - 关于苹果认证MFI
@component(““)
2022-07-06: will the following go language codes be panic? A: Meeting; B: No. package main import “C“ func main() { var ch chan struct
随机推荐
Route jump in wechat applet
nacos
Tianqing sends instructions to bypass the secondary verification
基于Flask搭建个人网站
Write CPU yourself -- Chapter 9 -- learning notes
[Stanford Jiwang cs144 project] lab3: tcpsender
pytorch 参数初始化
[UTCTF2020]file header
[2022 actf] Web Topic recurrence
[2022 CISCN]初赛 web题目复现
4、 High performance go language release optimization and landing practice youth training camp notes
I failed in the postgraduate entrance examination and couldn't get into the big factory. I feel like it's over
Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
Make a bat file for cleaning system garbage
按键精灵采集学习-矿药采集及跑图
图解GPT3的工作原理
php导出百万数据
Simple example of ros2 planning system plansys2
The configuration that needs to be modified when switching between high and low versions of MySQL 5-8 (take aicode as an example here)
《动手学深度学习》(四) -- 卷积神经网络 CNN