Dynamic pointers to pointers ...anyone?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <cstdlib>
#include <iostream>
#include <string>


using namespace std;



int main(){

	int **mptr=NULL, *childptr=NULL, ar[3] = {5,1,9};

mptr = (int**) realloc (mptr,3*sizeof(int*));
mptr[0] = (int * ) malloc (4*sizeof(int));

childptr = (int*) malloc(4*sizeof(int));
childptr[0]=6; childptr[1]=9; childptr[2]=3; childptr[3]=1;

*mptr[0]=2;

mptr[1]=childptr;
mptr[2]= ar;

cout<<*mptr[1];
cout<<*mptr[2];
return 0;

}


ok, i can read childptr's position 0. its number6. but how to read childptr[1],[2],[3] ? and, *mptr[2] really points to ar[0]. but how to iterate to ar[1],[2] ?...kindaaa... *mptr[1->3]? *mptr[1.3]? ok its foolish i know im just trying to figure out :))
Last edited on
1
2
3
4
5
6
7
8
9
10
cout << *mptr[1] << endl; //prints 6
cout << mptr[1][0] << endl; //also prints 6
cout << mptr[1][1] << endl; //prints 9
cout << mptr[1][2] << endl; //prints 3
cout << mptr[1][3] << endl; //prints 1

cout << *mptr[2] << endl; //prints 5
cout << mptr[2][0] << endl; //also prints 5
cout << mptr[2][1] << endl; //prints 1
cout << mptr[2][2] << endl; //prints 9 
AAAAHHHHH do you know how many hours i was trying to figure that out???? im such a dumb asshole no i dont diserve to be a programmer kill me sh00t me in a head!!!! i was putting *mptr[1][1] thats why, i should have used it without direferencing. ...thanks for help bless you ................. hey i know 3d graphycs ask me if something ill teach you everything i know.
do you know how many hours i was trying to figure that out????

"Wasting" time on things that don't work, only to then figure out a simple solution is unavoidable in programming. Get used to it ;)
Topic archived. No new replies allowed.