33.2 Practice doubts - C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

33.2 Practice doubts - C++

Hi there, facing the test in the title, I have a few doubts I was hoping someone could help me to solve. First of all, the quiz seems to be solved even without using any pointer or dynamic memory (which should be the main goal of the practice). Why should we use a pointer instead of just int nums[n]{}; as a declaration? Second question: when deleting the pointer, should we include the array snippet or not? Full code here https://code.sololearn.com/clIiwtDKzKeh/?ref=app

18th Jul 2021, 11:45 AM
Filippo C.
Filippo C. - avatar
1 Answer
+ 3
"Why should we use a pointer instead of just int nums[n] {}; In array declaration?" About this one, I would suggest you to search the net for "variable length array" in regards to C++. As I understand, variable length array (short: VLA) is not part of C++ standard, only some compilers implemented VLA as an extension. So VLA is not recommended for the sake of code compatibility, I think. Because if your code use VLA, then your code may not be processed smoothly in standard compliance compilers that does not implement VLA (cmiiw).
18th Jul 2021, 1:07 PM
Ipang