Hey!
I was reading about dynamic memory allocation, and I don't quite get the purpose of it. It says, you can create pointer to an array you don't know the size
of yet. Why not create an array during rutime, using a variable as a size?
Below is an example of what I mean.
With dynamic array:
Without:Code:int v, *dynarr; cin >> v; cin.ignore(); dynarr = new int [v]; cout<<"\n"; for (int x = 0; x<v; x++){ dynarr[x]=v; cout << dynarr[x]; }
Those two pieces of code do the same thing, so what is the advantage of creating a pointer to an array again?Code:int v; cin >> v; cin.ignore(); int dynarr[v]; cout<<"\n"; for (int x = 0; x<v; x++){ dynarr[x]=v; cout << dynarr[x]; }