Stack array initialization with user input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Stack array initialization with user input

I tried this: I took an int 'size' as user input and then went and declared an array using the variable for determining its size: char arr[size]; And it worked, not only here but also on my PC. No error, no warning, both in C and C++. I thought that non-heap variables of all sorts must be defined at compile time; but logically, the length of the array will only be known at runtime. Can someone explain me how and why this works?

15th Jan 2019, 8:47 PM
HonFu
HonFu - avatar
1 Answer
15th Jan 2019, 10:40 PM
MO ELomari