当前位置:网站首页>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; }
边栏推荐
- 【经验分享】如何为visio扩展云服务图标
- 4、 High performance go language release optimization and landing practice youth training camp notes
- php导出百万数据
- SQL优化的魅力!从 30248s 到 0.001s
- IO流 file
- Technology cloud report: from robot to Cobot, human-computer integration is creating an era
- Regular e-commerce problems part1
- [webrtc] M98 screen and window acquisition
- 微信小程序中的路由跳转
- [mathematical notes] radian
猜你喜欢
Write CPU yourself -- Chapter 9 -- learning notes
nacos
[UTCTF2020]file header
nacos
今日现货白银操作建议
The configuration that needs to be modified when switching between high and low versions of MySQL 5-8 (take aicode as an example here)
leetcode:105. 从前序与中序遍历序列构造二叉树
Redis data migration
Codeforces Global Round 19
[UTCTF2020]file header
随机推荐
A bit of knowledge - about Apple Certified MFI
Resource create package method
开源生态|打造活力开源社区,共建开源新生态!
解决:Could NOT find KF5 (missing: CoreAddons DBusAddons DocTools XmlGui)
Talk about seven ways to realize asynchronous programming
Tencent's one-day life
[webrtc] M98 screen and window acquisition
misc ez_ usb
【数学笔记】弧度
idea添加类注释模板和方法模板
gatk4中的interval是什么??
Invalid table alias or column reference`xxx`
Weibo publishing cases
About some details of final, I have something to say - learn about final CSDN creation clock out from the memory model
Live online system source code, using valueanimator to achieve view zoom in and out animation effect
Route jump in wechat applet
基于Flask搭建个人网站
Why is the row of SQL_ The ranking returned by number is 1
Leetcode sword finger offer brush questions - day 20
智联+影音,AITO问界M7想干翻的不止理想One