I am trying to improve my understanding of pointer. i know that there are smart pointers and vector/array containers in c++ now and i should use them as that would be the appropriate 'c++' way of doing things. But i am doing it the crude way for learning purposes.
In the following code, i am pointing a 'pointer' to a dynamically allocated array of size 5. I then try to place a character ('z') at each index of array and increment the pointer to make it point to next index.
In the second 'for' loop, i bring the pointer back 5 paces(to the start of the array)
In the third for loop, i simply display the values at eack index of the array by using pointer notation again.
The result that i am getting is incorrect. 'z' is displayed 20 times where as i think it should be 5 times as the array is of size 5. Can somebody explain the error. Debugging is not of much help to me.