initializing static variable with a function call gives compilation error?

后端 未结 3 734
醉话见心
醉话见心 2020-12-19 04:52
#include 
int foo(){
    return 1;
}
int main(void) {
    static int q = foo(); 
    return 0;
}

Here is a link for the same. This i

3条回答
  •  臣服心动
    2020-12-19 05:26

    If you are doing this in C rather than C++ you can only assign static variables values that are available during compilation. So the use of foo() is not permitted due to its value not being determined until runtime.

提交回复
热议问题