koebehshian
250 天前
The C Programming Language 附录 A ,A.8 Declarations 中说:
```
Declarations specify the interpretation given to each identifier; they do not necessarily reserve storage associated with the identifier. Declarations that reserve storage are called definitions.
```
所以,首先要明白,definition 是 declaration 的一种,区别在于 definition 为变量预留了内存
所以,你的问题应该修改为:int a; 有没有预留内存。
答案是:大多数情况下预留了内存。只有一种情况,就是写在函数外面
A.10.2 External Declarations 中说:
```
An external object declaration that does not have an initializer, and does not contain the extern specifier, is a tentative definition. If a definition for an object appears in a translation unit, any tentative definitions are treated merely as redundant declarations.
```
意思是,int a; 写在函数外面,编译器先会将其待定;如果发现整个编译单元(一般是一个预处理过的源文件)中有多个这样的写法,则多余的就被当作没有预留内存的 declarations 了