Hello guys,
I'm a beginner at c++ and in a few days I have an exam but there are some things I don't understand in the example cpp file that my teacher sent me.
So I would like to ask for help. Can some one explain to me what is the meaning of declaring a " new double " and why should we delete it at the end ?
x is an array of pointers to doubles. It is 3 elements big.
x[0] is the address of v[2]
x[1] is the address of y
newdouble[2] allocates an array of double of size 2 from the heap. That value is assigned to x[2]. So it's valid to do x[2][0] and x[2][1] to get to these values.
everything kbw said, plus you have to delete everything that you new.
new will allocate memory, delete will deallocate it. if you just new without delete then you will keep allocating without deallocating, and eventually consume all of your memory.