Why can't I create an array with size determined by a global variable?

前端 未结 7 625
北海茫月
北海茫月 2020-11-27 06:11

Why does the array a not get initialized by global variable size?

#include

int size = 5;

int main()
{
    int a[si         


        
相关标签:
7条回答
  • 2020-11-27 06:39

    The compiler cannot assume that the value of size is still 5 by the time main() gets control. If you want a true constant in an old-style C project, use:

    #define size 5
    
    0 讨论(0)
提交回复
热议问题