Why can't I create an array with size determined by a global variable?
- by ashish yadav
Why does the array a not get initialized by global variable size?
#include<stdio.h>
int size=5;
int main()
{
int a[size]={1,2,3,4,5};
printf("%d",a[0]);
return 0;
}
The compilation error is shown as "variable-sized object may not be initialized".
According to me the array should get initialized by size.