0

Help me with dynamic memory allocation in C

I saw in a YouTube video that arrays in C can't be allocated with values that are given during runtime. But when I try that in my compiler, it actually works. I'm able to define and work with an array that is defined at runtime with user given value. Please explain this. Thank you already 🙂👏

5th Jun 2021, 9:13 AM
Rishi
Rishi - avatar
3 odpowiedzi
+ 4
Variable length array (VLA) are allowed in C ( means you can do something like "arr[n]" ) But doing so is generally considered as a code smell, as it opens a potential risk of having a huge array in your stack memory leaving little to no space for rest of the stuff and making your program highly vulnerable to memory stack overflow. P.S. It is only allowed in C. C++ standards doesn't allow VLAs ( although some cpp compiler may implement it as an extension, it is highly recommended to choose an stl alternative like std::vector instead )
5th Jun 2021, 9:46 AM
Arsenic
Arsenic - avatar
+ 1
Arsenic oh okay thank you
5th Jun 2021, 11:25 AM
Rishi
Rishi - avatar