Definition of global variables using a non constant initializer

后端 未结 4 1415
夕颜
夕颜 2020-12-03 22:39
#include 

int i=10;
int j=i;
int main()
{
    printf(\"%d\",j);
}

I get an error stating that initialization element is not a const

4条回答
  •  执念已碎
    2020-12-03 23:19

    What is the reason behind this?

    C(unlike C++) does not allow initialization of global values with non constant values.

    C99 Standard: Section 6.7.8:

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

提交回复
热议问题