Global variable local variable static dynamic static auto register extern

Global variable

When global variables are not initialized, the system defaults to 0; local variables have no default value.

1. Static external variables (only this text) (add static)
2. External variables (neither static external variables, other file references are allowed)

Local variable

Automatic variables, both dynamic local variables (will disappear when leaving the function value) (auto auto)
static local variables (leave the function value retained) (using static)
register variables (leave the function value disappear)
(formal parameters can be defined as automatic variables or Register variable)
If the value of a local variable does not want to be released, add static before the value of the local variable will become static;
if the value of a global variable does not want to be referenced by other files, just use it in the file where it is located Add static before;

static int a; //静态局部整形变量或静态外部整形变量;
			//函数中变量不随函数结束就消失,而保留原值,空间不释放。
auto char c;//自动变量,在函数内定义;
           //局部变量如果不专门声明为static(静态)存储类别,都自动默认为auto动态存储区中。

register int d;//寄存器变量,在函数内定义;
            //以前版本低,运算器与内存互交流工作,导致变量使用频率过多时就会存储和拿出运算,
			//使计算变慢,所以次函数,将所用变量暂时放入CUP存储器中。
			//对于常使用的变量,减少运算时间,就将本该存放在内存中的值,暂时存放在CPU中直接运算。
			//现在系统自动识别使用频率高的自动放入CPU的寄存器中。
extern a;//将已定义外部变量a的作用域引用至此(可跨文件引用)

Guess you like

Origin blog.csdn.net/weixin_52270223/article/details/110149100