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

Posted by ashish yadav on Stack Overflow See other posts from Stack Overflow or by ashish yadav
Published on 2010-03-11T17:48:37Z Indexed on 2010/03/11 17:59 UTC
Read the original article Hit count: 224

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about c

    Related posts about global-variables