In the below program, when does the array c gets initialize ?
If is it at compile time then how I got the output as 20 which is the product of n i.e. 5 and size of integer in C++ i.e. 4 ,after I pass the value of n at runtime. And if it got allocated at runtime then, how is it possible ,as for runtime allocation we have to use new operator which is not use in this program.
Asked
Active
Viewed 274 times
0

Krishna Salampuriya
- 121
- 1
- 6
-
[Some useful reading](https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html). Note that is just with respect to g++'s implementation of VLAs. – user4581301 Nov 25 '20 at 17:08
-
I tried to paste your code into my IDE, but my IDE doesn't support images. Please post your code as text (highlight the text, copy to clipboard, then paste into your question). No code pasted as text == no help. – Thomas Matthews Nov 25 '20 at 17:41
-
To answer the *title* of your question, arrays are allocated as contiguous units of memory. Where the memory is, depends on where the declaration is or whether you use dynamic allocation. If you want an array whose size is determined at run-time, use `std::vector`. – Thomas Matthews Nov 25 '20 at 17:43