auto 存储类说明符auto Storage-Class Specifier

auto 存储类说明符可声明自动变量,即具有本地生存期的变量。The auto storage-class specifier declares an automatic variable, a variable with a local lifetime. auto 变量仅在声明它的块中可见。An auto variable is visible only in the block in which it is declared. auto 变量的声明可包含初始值设定项,如初始化中所述。Declarations of auto variables can include initializers, as discussed in Initialization. 由于具有 auto 存储类的变量不会自动初始化,因此应该在声明这些变量时对其进行显式初始化,或在块的语句中为其分配初始值。Since variables with auto storage class are not initialized automatically, you should either explicitly initialize them when you declare them, or assign them initial values in statements within the block. 未初始化的 auto 变量的值是不确定的。The values of uninitialized auto variables are undefined. (如果给定了初始值设定项,则每次 auto 或 register 存储类的局部变量进入此范围时都会被初始化。)(A local variable of auto or register storage class is initialized each time it comes in scope if an initializer is given.)

内部 static 变量(具有本地或块范围的静态变量)可以使用任何外部或 static 项的地址进行初始化,但不能使用另一个 auto 项的地址进行初始化,因为 auto 项的地址不是常量。An internal static variable (a static variable with local or block scope) can be initialized with the address of any external or static item, but not with the address of another auto item, because the address of an auto item is not a constant.

请参阅See Also

auto 关键字auto Keyword