0

When the VLAs are declared in local space they work fine (unless -pedantic is used):

 int main()
 {
     int i=9;
     char n[i];   


     return 0;
 }

But when the same is done at global level it throws an error

int i=9;
char n[i];    //error: array bound is not an integer constant before ‘]’ token

int main()
{

     return 0;
}
  • is it because the contents of the local space are present in stack and contents in static memory require the size beforehand?

The compiler is g++ (GCC) 8.2.0

infinite
  • 319
  • 1
  • 10

0 Answers0