Hi, I was recently reading a tutorial on C++ and I had a question about dynamic memory.
The first paragraph of the tutorial stated the following:
"Until now, in all our programs, we have only had as much memory available as we declared for our variables, having the size of all of them to be determined in the source code, before the execution of the program. But, what if we need a variable amount of memory that can only be determined during runtime? For example, in the case that we need some user input to determine the necessary amount of memory space.
The answer is dynamic memory, for which C++ integrates the operators new and delete."
It talks about the following
int * bobby;
bobby = new int [5];
and
delete pointer;
delete [] pointer;
My question is that even without using the new and delete can I not use the basic approach to dynamic memory. For example can I not just do this:
int i;
int array[i];
cin>>i;
now we have an array with size i, and that will be adjusted according to the input given.
So, what is the use of using "new" operator?
THANK YOU!