Difference between initialization of static variables in C and C++

后端 未结 3 1532
鱼传尺愫
鱼传尺愫 2020-12-11 00:26

I was going through the code at http://geeksforgeeks.org/?p=10302

#include
int initializer(void)
{
    return 50;
}

int main()
{
    static i         


        
3条回答
  •  生来不讨喜
    2020-12-11 01:04

    Static variables in C need to be initialised with a value known at compile time. This requirement has been removed in C++, and you can initialise them with expressions evaluated at run-time.

    The two languages differ in this, and many, many other respects. You can quite easily write C code which will be acceptable to a C++ compiler, but the reverse is not true.

提交回复
热议问题