If I want to declare a dynamic size array in the main function, I can do:-
int m;
cin>>m;
int *arr= new int[m];
The following cannot be done as while compiling the compiler has to know the size of the every symbol except if it is an external symbol:-
int m;
cin>>m;
int arr[m];
My questions are:
Why does the compiler have to know the size of arr in the above code? It is a local symbol which is not defined in the symbol table. At runtime, the stack takes care of it(same way as m). Is it because the compiler has to ascertain the size of main() (a global symbol) which is equal to the size of all objects defined in it?
If I have a function:
int func(int m)Could I define int arr[m] inside the function or still I would have to do
int *a= new int[m]