c语言中全局变量和静态变量
Prerequisite: Storage classes in C
先决条件: C语言中的存储类
Automatic (auto) and static both are the keywords which are used under the storage classes, and they define the scope, lifetime, default value and memory segment of the variables.
自动( auto )和静态都是在存储类下使用的关键字,它们定义变量的范围,生存期,默认值和内存段。
1)自动('auto')变量 (1) Automatic (‘auto’) variable)
The all local variables which are defined within the function are known as auto (automatic) variables unless not specified i.e. by default a local variable is an auto variable. There is no need to put the keyword auto (it’s an optional) while declaring a local variable.
除非未指定,否则函数中定义的所有局部变量都称为自动 (自动)变量,即默认情况下,局部变量是自动变量。 在声明局部变量时,无需放置关键字auto (它是可选的)。
An auto variable created a new each time when the function (in which variable is declared) is called and destroyed when the program’s execution leaves the function.
每次调用函数(在其中声明变量)时都会创建一个新的自动变量,并在程序执行离开该函数时销毁该变量。 </