当前位置:网站首页>C language -- 8 familiar keywords
C language -- 8 familiar keywords
2022-06-10 21:35:00 【Try!】
1、 keyword
Keywords are C Language provides , You can't create your own keywords ;
Keyword cannot be used as variable name ,eg:int char; This kind of writing is not advisable .
2、 Common keywords
auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unisigned void volatile while The above listed are all common keywords .
(1)auto It's automatic , Every local variable is auto Embellished , Such as : In the structure, there is
{
int a =10;
}
This is actually an automatic creation 、 Automatically destroyed , Is an automatic variable , It is omitted from the front auto, It's actually auto int a =10;
(2)extern: Used to declare external variables
(3)register: Register key
int main()
{
register int num = 100;// Refers to recommendations num Put the value of in the register
return 0;
}
In the computer , Data can be stored in “ register ”、“ Cache ”、“ Memory ”、“ Hard disk ”、“ Network disk ” These places .
From bottom to top , The cost is getting higher and higher , The space is getting smaller and smaller , But the speed of reading and writing is getting faster and faster .
take “ A lot of ” perhaps “ frequent ” Data used , Put it in the register , You can improve efficiency .
(4)signed: The signed unsigned: Unsigned
(5)static: Static
In language ,static Is used to modify variables and functions .
- Modify local variables ---- Static local variables , Changing the life cycle of local variables ( In essence, it changes the storage type of variables )
- Modify global variable — Static global variables
- Modify function — Static functions
1>static Modify local variables
Statement test function
void test()// Statement test function
{
int a = 1;
a++;
printf("%d",a);
return 0;
}
int main()
{
int i = 0;
while (i < 10)
{
test();
i++;
}
return 0;
}
The running result is :2222222222
If the test Function int a=1; Change it to static int a =1;, Then the running result is 234567891011.
Add :
Memory can be divided into “ The stack area ”( Store local variables )、“ Heap area ”( Dynamic memory allocation ) as well as “ Static zone ”( Store global variables and ststic Decorated static variables ). So in this example ,a From stack area to static area , Its storage type has changed , Further lead to life cycle change . The program doesn't end , Global variables and static Decorated static variables are not destroyed .
2>static Modify global variable
Global variables can be used throughout the project , But be static After decoration, it can not be used in the whole project , If you write in a source file static int g_val=2022;, Write in another source file :
An error will be reported after clicking run , Show unresolved external symbols g_val
static Modifying a global variable will make the global variable only in its own .c In the source file , Other source files cannot be used .
Global variables can be used inside other source files , Because global variables have external link properties , But be static After retouching , It becomes an internal link attribute , Other source files cannot be linked to this static global variable .
3>static Modify function
Write in a source file
int Add(int x, int y)
{
return x + y;
}
Write in another source file
extern int Add(int x,int y)
int main()
{
int a = 10;
int b = 20;
int sum = Add(a,b);
printf("sum=%d\n",sum);
return 0;
}
It can be executed in this way , But will int Add(int x, int y) Change it to static int Add(int x, int y) You're going to report a mistake , Show unresolved external symbols .
static Decorate a function so that it can only be used inside its own source file , Cannot be used in other source files , Essentially, static Change the external link property of the function into an internal link property , and static Modify global variables .
(6)struct: Structure keywords
(7)typedef: Type redefinition
The following code is to define an unsigned integer , But it's a little troublesome to write like this , So I used typedef keyword .
int main()
{
unsigned int num = 100;
return 0;
}
utilize typedef Keyword for type redefinition :
typedef unsigned int u_int;
// It means that unsigned int Rename as u_int, In the following code ,u_int It stands for unsigned integer
int main()
{
u_int num1 = 100;
return 0;
}
(8)union: Consortium ( Shared body )
(9)void: nothing , empty
(10)volatile
ask :define And include Is it a keyword ?
answer : They are not keywords , They are preprocessing instructions .
边栏推荐
- Redis缓存击穿
- Power set V4 recursion of brute force method /1~n
- Rotate menu 2.0
- Leetcode advanced road - 136 A number that appears only once
- Extracting Nalu unit data from H264 real-time stream
- [Warning] TIMESTAMP with implicit DEFAULT value is deprecated
- Leetcode advanced path - the first unique character in a string
- C language -- 4 first-time constant
- Lengsuanling, a 30-year tortuous history of IPO of a domestic brand
- 01js basic null and undefined difference type conversion = = code block logical operator
猜你喜欢

Meetup预告:Linkis新版本介绍以及DSS的应用实践
![[Warning] TIMESTAMP with implicit DEFAULT value is deprecated](/img/e8/53c18a7944d160238f2f1c0f8f04b1.jpg)
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated

保姆级教程:如何成为Apache Linkis文档贡献者

Introduction to database system -- Chapter 1 -- Introduction (important knowledge points)

学IT毕业后该去哪个城市?哪个岗位薪资高?哪些公司待遇好?

Redis cache penetration

Vissim仿真快速入门

微积分复习1

LeetCode:1037. Effective boomerang - simple

详解MATLAB中与矩阵运算有关的算术运算符(加、减、乘、除、点乘、点除、乘方)
随机推荐
leetcode 划分数组使最大差为 K
^29 event cycle model
C language -- 4 first-time constant
Standard dual airbags, starting from 48900 for butcher Chang'an Lumin
Codeforces Round #798 (Div. 2)
异步、线程池(CompletableFuture)
蛮力法/1~n的全排列 v3 递归
A small case with 666 times performance improvement illustrates the importance of using indexes correctly in tidb
C language ---2 initial knowledge of data types
shell实现ssh登录并执行命令
Leetcode advanced road - 125 Validate palindrome string
Leetcode advanced path - delete duplicates in the sorting array
Brute force method / task assignment
旋转导航栏
Lengsuanling, a 30-year tortuous history of IPO of a domestic brand
A small case with 666 times performance improvement illustrates the importance of using indexes correctly in tidb
LeetCode 进阶之路 - 反转字符串
自制Table錶格
Leetcode advanced road - 167 Sum of two numbers II - input ordered array
Meetup预告:Linkis新版本介绍以及DSS的应用实践