Possible duplicate:
Dynamic array on stack?
How compilers handle variable-length arrays
Someone I taught wrote some piece of code that looked like this: it compiled, worked correctly, and made me feel like a complete C ++ newbie in this process:
int main(int argc, char** argv) { int Index=0; cin>>Index; int Test_array[Index][Index]; ... }
Now I have found the answer to the question why this works here: about an array in C
However, I still have a survey on how.
I mean, should the stack size for code blocks be known in advance? So, of course, Test_array cannot be stored on the stack ...
Does the compiler write a new / malloc -delete / free operation behind the hood to use heap memory for the array?
In that case, if such code throws a bad_alloc exception, if enough memory is not found in the heap?
source share