当前位置:网站首页>In depth anatomy of C language - key words & supplementary contents
In depth anatomy of C language - key words & supplementary contents
2022-06-12 12:28:00 【Muxixi】
Hello, I'm Mu Xixi

List of articles

Keyword classification
In ordinary books ,C Language keywords are 32 individual , But this is all C90(C89) Standards for . Actually C99 And then I added 5 Key words . however , Current mainstream compilers , Yes C99 The support is not good , according to C90 standard , The idea that 32 individual .
| keyword | explain |
|---|---|
| auto | Declare automatic variables |
| short | Declare short integer variables or functions |
| int | Declare an integer variable or function |
| long | Declare long integer variables or functions |
| float | Declare floating-point variables or functions |
| double | Declare a double precision variable or function |
| char | Declare character type variables or functions |
| struct | Declare a structural variable or function |
| union | Declare shared data type |
| enum | Declare enumeration type |
| typedef | Used to alias data types |
| const | Declare read-only variable |
| unsigned | Declare an unsigned type variable or function |
| signed | Declare a symbolic type variable or function |
| extern | Declare variables are being declared in other files |
| register | Declare register variables |
| static | Declare static variables |
| volatile | Explain that variables can be implicitly changed during program execution |
| void | Declares that the function returns no value or takes no arguments , Declare no type pointer |
| if | Conditional statements |
| else | Conditional statement negates Branch ( And if Continuous use ) |
| switch | For switch statements |
| case | Switch statement Branch |
| for | A circular statement |
| do | The body of a loop statement |
| while | The loop condition of a loop statement |
| goto | Jump statements without conditions |
| continue | End the current cycle , Start next cycle |
| break | Jump out of current loop |
| default | In the switch statement “ other ” Branch |
| sizeof | Calculate the data type length |
| return | Subroutine return statement ( With parameters , Or without parameters ) The loop condition |
Supplementary content
first C Program
#include<stdio.h>
#include<windows.h>//windows.h System header file , Just to stop the screen
int main()
{
printf("hello world!\n");
system("pause");//pause Stop screen
return 0;
}
The file code is converted into an executable program after generating the solution ( Binary .exe)
You can empty the executable by emptying the solution 
- stay windows in , Double click the essence of the program to run it , Load the program into memory .
- Any program must be loaded into memory before it can be run .
- Load into memory , Fast .
Von Neumann 
Definitions and statements
Variable
stay Memory Open up a specific size of space in , To hold data
Definition of variables
type Variable name = The default value is
int a = 10;
char c = 'c';
Define the reason for the variable : Because there is data that needs to be saved temporarily , Waiting for further processing .
The nature of variables
- The essence of all variables is to open up space somewhere in memory .
- The program runs , It needs to be loaded into memory
- Program calculation , You need to use variables
Define the nature of variables : Open up a space in memory , To hold data .( Why must it be memory : Because defining variables , It's also part of program logic , The program has been loaded into memory )
Definition : Open up space , There can only be one time .
Statement : inform , Many times .
int a = 10;//a The definition of
a = 20;// assignment
a = 100;// assignment
Classification of variables
Variables are divided into : Local and global variables
local variable : The variables contained in the code block are called local variables . Local variables are temporary . Enter code block , Automatically form local variables , The exit code block is automatically released .[ Many on the Internet say that the variables in the function are local variables , You can't say wrong , But the statement is inaccurate ]( Defined in a code block )
Global variables : Variables defined outside all functions , It's called a global variable . Global variables are global .( Defined outside the code block )
Code block : use {} The enclosed area , It's called a code block
#include<stdio.h>
int g_val = 100;// Global variables
int main()
{
int a = 10;// local variable ,main Functions are also functions , There are also code blocks {}
if(a == 10)
{
int b = 10;// local variable
}
printf("a=%d\n", a);
return 0;
}
Scope of variable
Scope : It refers to the code area of the variable that can be accessed normally .
local variable : Valid only within this code block .
Global variables : During the whole program running , Are effective .
Where global variables :
- Can be accessed in any code block
- Can be accessed in any code block , Even modified .
- When a global variable has the same name as a local variable , Local variables take precedence .
#include<stdio.h>
int g_vax = 10;// Global variables
void test()
{
int g_val = 100;// Of a local variable g_val Can only be accessed in this code
printf("%d\n", g_val);// In global variables g_val Any code block can be accessed , Even modified
// The output is local , That is, when part and all have the same name , Preferential local .
}
int main()
{
test();
printf("%d\n", g_vax);// Can be accessed in any code block
return 0;
}

Life cycle of variable
Life cycle concept : It refers to the time range from the definition of the variable to its release , The so-called release , It refers to the space once opened up ” Be released “.
local variable : Enter code block , Form local variables [ Open up space ], Exit code block ," Release " local variable .
Global variables : After definition , Throughout the life cycle of the program , This variable is always valid .
Scope vs Life cycle
Scope : Measure the extent of the variable's impact , The valid scope of this variable .
Life cycle : Describes the length of a variable's lifetime . The concept of time : When was it opened up , When is it released .

The most generous keyword - auto
How to use : Variables typically defined in code blocks , Local variable , The default is auto Embellished , But generally omit .
By default, all variables are auto Do you ? No , Generally used to modify local variables
Local variables include automatic variables , Temporary and local variables .
#include <stdio.h>
int main()
{
for (int i = 0; i < 10; i++) // local variable i Can also be auto modification
{
printf("i=%d\n", i);
if (1)
{
auto int j = 0;// Automatic variable
printf("before: j=%d\n", j);
j += 1;
printf("after : j=%d\n", j);
}
}
return 0;
}

auto Already very old , Basically not used .
The fastest keyword - register
CPU It is mainly the hardware unit responsible for calculation , But for ease of calculation , Generally, the first step is to read the data from memory to CPU Inside , Then you need CPU It has certain temporary data storage capacity . Be careful :CPU It's not the time to calculate , To read specific data to CPU Inside , That's too slow .
So modern CPU Inside , Are integrated with a set of hardware called registers , Used to save temporary data .
Storage pyramid

distance CPU The closer the storage hardware , The faster the speed. .
Understanding of register
CPU A set of storage hardware is integrated into the , This set of hardware is called registers .
The essence of register existence
On the hardware level , Improve the computing efficiency of the computer . Because you don't need to read data from memory .
register Modifying variables
As far as possible The modified variable , Put in CPU In the deposit area , So as to achieve the purpose of improving efficiency
So what kind of variables , May adopt register Well ?
1. Local ( The overall situation will lead to CPU The register is occupied for a long time )
2. Will not be written ( Writing requires writing back to memory , If you need to read the test later , It doesn't make sense )
3. High frequency read ( Improving efficiency lies in )
4. If you want to use , Please don't use a lot of , Because the number of registers is limited
5.register Decorated variable , Address not available ( Because it's already in the deposit area , Address is a memory related concept )
register –cache– Memory –SSD/flash/ Hard disk – Compact disc – disk
Hard disk is converted into memory through cache technology , Memory is converted into registers through cache technology .
distance CPU The nearer the storage unit , The more efficient , The higher the unit price cost .
distance CPU The farther away the storage unit , The less efficient , The cheaper the unit price .
For any kind of hardware , Act as a cache for upstream hardware .
example : Memory can be regarded as a large cache of hard disk ;cache And registers are equivalent to some kind of cache in memory .
CPU When accessing data , Achieve the highest efficiency at the lowest cost .
#include<stdio.h>
int main()
{
register int a = 10;
printf("%p\n", &a);
return 0;
}

At the end
Friends who think it's good can pay attention to , Like or collect ! Thank you for your support .
Yours ️ Praise is the source of my creative power
Your collection is the direction of my struggle
Your attention is my greatest support
Yours ️ Comments are a bright light for me to move forward
It's not easy to create , I hope you can support Xiaomu
边栏推荐
- Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference
- 左右案例+小圆点的轮播图+无时间
- Problems encountered in installing canvas and errors encountered in running the project
- TRON-api-波场转账查询接口-PHP版本-基于ThinkPHP5封装-附带接口文档-20220528版本
- JS string array converted to numeric array and how to add the numbers in the array
- AutoLock 解决加锁后忘记解锁问题
- Traditional DOM rendering?
- Find the median of two ordered arrays (leetcode 4)
- Chapter VI data type (V)
- Create servlet project
猜你喜欢

VGG小卷积代替大卷积 VS 深度可分离卷积

Numpy数值计算基础

JS how to convert a string into an array object

Performance comparison test of channel and condition variables of golang in single production and single consumption scenarios

【Leetcode】79. Word search

Promise knowledge

KDD2022 | 边信息增强图Transformer

In navigation, the solution of adding borders to affect the layout

Video speed doubling in PC browser

Reprint --win10 open the task manager to solve the blue screen problem
随机推荐
2021-11-16
this的指向
Beyondcompare 4 uses PJ
Take the web page animation effects that can be used. Don't you come and have a look?
LeetCode_ Binary search_ Medium_ 162. looking for peaks
BAT面试&高级进阶,文末领取面试资料
mysql复习
Principle of master-slave replication of redis
从小白入手,从已经训练好的模型中取出weight权重参数绘制柱状图
TRON-api-波场转账查询接口-PHP版本-基于ThinkPHP5封装-附带接口文档-20220602版本-接口部署好适用于任何开发语言
DOM+JS+轮播图+无时间
关系代数笛卡尔积和自然连接的例子
Performance comparison test of channel and condition variables of golang in single production and single consumption scenarios
Various data transmission
回溯法, 八皇后
KDD2022 | 边信息增强图Transformer
Bat interview & advanced, get interview materials at the end of the text
JS pre parsing, object, new keyword
Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference
promise的理解已经利用promise实现图片的预加载(顺序加载)