且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

局部变量的自动初始化

更新时间:2023-11-10 20:44:16

它具有不确定的价值.它可以是任何东西.

It is having indeterminate value. It can be anything.

引用 C11 §6.7.9

如果没有显式初始化具有自动存储期的对象,则其值为不定.[...]

If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate. [...]

自动局部变量,除非明确初始化,否则将包含不确定值.如果您尝试使用一个变量而它持有不确定的值,或者

Automatic local variables, unless initialized explicitly, will contain indeterminate value. In case you try to use a variable while it holds indeterminate value and either

  • 没有获取地址
  • 可以有陷阱表示

使用将导致未定义行为.