gpt4 book ai didi

c - C中外部变量的初始化

转载 作者:行者123 更新时间:2023-11-30 15:38:57 24 4
gpt4 key购买 nike

我是 C 的新手。我在读 Kernighan & Ritchie 的书,发现外部变量只能用常量表达式初始化。为什么会这样呢?你能解释一下内部发生了什么吗?它们什么时候初始化?为什么我们不能使用之前定义的外部变量来初始化外部变量?

最佳答案

根据C99标准:第6.7.8节:

All the expressions in an initializer for an object that has static storage duration shall be constant expressions or string literals.

并且外部变量具有静态存储期限,因此必须通过常量表达式或字符串文字进行初始化。

关于c - C中外部变量的初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21619607/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com