I having a confusion about what is going on behind the scene of array initialization.
int n= 3;
int a[n]; // compile succeeds
but,
int n = 3;
int a[n] = {1, 2, 3}; // compile error
error message from codeblock:
error: variable-sized object 'a' may not be initialized
My understanding is:
first snippet, n elements are allocated but uninitialized. Second one allocates n elements and initializes them to {1, 2, 3}. Both do almost the same thing, but why second one causes error.
Please clarify my understanding or leave me some resources (I've tried, but couldn't find the close answer).
compiler: mingw32-g++
int a[n];is not standard and should not compile.