int a[5] = {2,4,6,8,10}; // Works
But,
int a[5];
a = {2,4,6,8,10}; //Doesn't Work
Why?
Is there any other way in which I can initialize a array in a single go which is created before.
int a[5] = {2,4,6,8,10}; // Works
But,
int a[5];
a = {2,4,6,8,10}; //Doesn't Work
Why?
Is there any other way in which I can initialize a array in a single go which is created before.
I haven't tested it myself, but since C99 you should be able to use a compound literal with memcpy
to copy the data into the array:
memcpy(a, (int[5]){2,4,6,8,10}, sizeof a);