Hi I really need help figuring this one out I have been working at it forever. I am trying to pass an array of 3 pointers, which are themselves arrays, and get the sum of the last two pointers and store it in the first pointer. The pointerarrays are filled with large integer numbers with each digit of the integer in a certain index of the array. What I am having trouble with is referencing a certain index within each array to add them together, being as the arrays themselves are index's of another array. Here is what I have so far.

pointerarray[1] = *oper1array;       //Set integer arrays to indexs of
pointerarray[2] = *oper2array;       //array to be passed to function
pointerarray[0] = *sumarray;          //sum

void sum(int pointer[3], int N)
    for(int i=0; i<N; i++)            
       pointer[0] = pointer[1] + pointer[2];  

I know the for loop has no meaning as it is now, but it needs to and I don't know how to implement that. It should add the index values of pointer[1] and pointer[2] and place them in the same index values in pointer[0].

Edited by slicer: n/a

7 Years
Discussion Span
Last Post by Excizted

Maybe if you included a bit more code? It seems complicated what you're trying to do, at least I didn't really understand what your goal is from your post. Take a look at this example and let me know if it's any help.

int* array1 = new int[100]; // pointer to array of 100 ints. 
int* array2 = new int[50]; // pointer to array of 50 ints. 
int* array3 = new int[25]; // pointer to array of 25 ints. 
int* topArray[] = {array1, array2, array3}; // array of int pointers 
/* Then topArray could be in heap and addressed from a pointer, fx: */
int** topArrayPtr = &topArray; // pointer to array of pointers to array of ints 
// maybe it's &topArray[] actually

Well I dunno if this small sample crosses your problem, but there ya go anyway.


What I am trying to do is add two large numbers together, up to 20 digits, i.e. 137282554 + 1909782035125387. The sum function I put in my above post is supposed to add the two integers which are stored in two seperate arrays and put the sum into a third array. These 3 arrays are inside another array which is passed from the main program to the sum function.

The 3 arrays are essentially pointers to 3 other arrays not shown in my code above, with the same purpose. The point is to be able to change the value of these indirectly through pointer variables. I still have yet to figure it out. Thank you for trying!


Something like this?

int** mainArray = new int*[5]; // example number
for(int i = 0; i < 5; i++)
     mainArray[i] = new int[3]; // two numbers and a sum

void sumThem(int** mArray, int which)
     mArray[which][0] = mArray[which][1]+mArray[which][2];
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.