And each of these Pointers point to an int Array that is Dynamically Allocated.
int * firstIntPtr;
firstIntPtr = new int[sizeOfIntArray];
int * secondIntPtr;
secondIntPtr = new int[sizeOfIntArray];
int * sumPtr;
sumPtr = new int[sizeOfIntArray];
I've passed the Array of Pointers to a function outside of main that is suppose to add the firstIntPtr and secondIntPtr together cell by cell using the paper and pencil algorithm and then putting that in the sumPtr Array.
The problem i ran into is deals with the Array of Pointers, each Pointer in the array points to the address of the first cell of the first, second, and sum arrays. I am having difficultly getting the pointers to point to the last cell and working its way back to the beginning.
The code you posted suggests you are forgetting about the loop altogether, causing the issues you're seeing now.
Arrays are contiguous. Once you point to the first cell, you get to cell 2, cell 3, cell 4, by looping with a simple index. You don't have to "repoint" the pointers.
for (int i = 0; i < 5; ++i)
std::cout << ArrayOfPtrs[i] << "\n";
What do you get as output when that loop is executed? You get the numbers in the first array. So that is why I asked you, "where is your loop?"
Correct me if I am wrong, but isnt
a 2D array?
So the pointers get me to the address of the array, but how can i jump to the back of the array when all i have to access that array is the pointer itself?
I'm sorry, I'm not trying to be a pain. Just trying to understand this stuff for myself and learn from it.
Last edited by MSwezey; March 24th, 2010 at 10:03 PM.