我正在阅读一些关于外部人员的信息。
现在作者开始提到变量的声明和定义。
通过声明,他提到了以下情况:如果声明了一个变量
没有为其分配空间。
现在这让我感到困惑,因为我认为MOST时代的
当我在 C 中使用变量时,我实际上是在定义和声明它们,对吗?
IE。,
int x; // definition + declaration(at least the space gets allocated for it)
我想那么onlyC 中声明变量但未声明变量时的情况
定义它是当你使用:
extern int x; // only declaration, no space allocated
我做对了吗?
基本上,是的,你是对的。
extern int x; // declares x, without defining it
extern int x = 42; // not frequent, declares AND defines it
int x; // at block scope, declares and defines x
int x = 42; // at file scope, declares and defines x
int x; // at file scope, declares and "tentatively" defines x
正如 C 标准中所写,声明指定一组标识符的解释和属性和一个定义对于一个对象,导致为该对象保留存储。也标识符的定义是该标识符的声明.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)