加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

声明:K&R

发布时间:2020-12-16 04:55:30 所属栏目:百科 来源:网络整理
导读:我正在阅读K R的“C编程语言”第2章:“类型,运算符和表达式”,第2.4节,在那里我发现了以下语句: If the variable in question is not automatic,the initialization is done once only,conceptually before the program starts executing,and the initiali
我正在阅读K& R的“C编程语言”第2章:“类型,运算符和表达式”,第2.4节,在那里我发现了以下语句:

If the variable in question is not automatic,the initialization is
done once only,conceptually before the program starts executing,and
the initializer must be a constant expression.An explicitly
initialized automatic variable is initialized each time the function
or block it is in is entered; the initializer may be any expression.

以上几行不太清楚它们是什么意思?

解决方法

int a = 5;
int b = a; //error,a is not a constant expression

int main(void)
{
  static int c = a; //error,a is not a constant expression
  int d = a; //okay,a don't have to be a constant expression
  return 0;
}

只有d是一个自动变量,所以只允许d用其他变量初始化.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读