You seem to be laboring under a misconception. Yes, arrays use "zero based indexes". No, zero isn't one.
CODE
int* dynArray = new int[4];//Taking into account the zero index. Total of five elements.
Not five, four.
CODE
int array[4]; // size is 4, elements are numbered 0..3. There are four elements.
When you've allocated an array, that's it. It's done. It doesn't grow. Psionics gave one solution. You create a new array the size you want, copy the contents of the prior array to the new one, and drop the old one.
This limitation is a big reason linked lists are used. Hope this makes sense.
CODE
int* dynArray = new int[4];//Taking into account the zero index. Total of five elements.
//Then can I increase the size of the dynamic array to 6 elements and set the last element to a value by doing the following?
dynArray[4 + 1] = 384;
//I could just test it out. But I wish to understand how the compiler will handle this dynamic code.
It will probably crash, horribly. dynArray is only goo up to dynArray[3]. If you try to address it beyond that point, it will be writing a value somewhere else, possibly over the executing code itself. It won't be pretty. Unfortunately, as stated, arrays are not dynamic. If you want dynamic, look into the vector class.
This post has been edited by baavgai: 29 Sep, 2008 - 04:55 PM