pointer array parameter passing

Create a new Array on the Heap

Creating a new array on the heap basically means:

1) we create a row of new objects that are next to each other
2) We then have an index pointer pointing to it. A index pointer is a pointer pointing to the FIRST element of the array. That way, we can access the rest of the array. If there is no index pointer, we wouldn’t know how to access the rest of the array elements.

1) We create the row of new objects like so:

2) Then we create the index pointer and point to it like so:

That’s it, and what this looks like in memory is this:

ptr_to_array

The index pointer by default is pointing to the 1st, or 0th element of the array.
The reason why we have an index pointer is so that we can reference the whole array like so:

0th element *(arrayA)
1st element *(arrayA + 1)
2nd element *(arrayA + 2)
nth element *(arrayA + n)

Thus, you can display all the elements in an array via an for loop and simply using the index i to display whatever element you’d like. That is the most important purpose of the index pointer.