[HELP] Pointer help

Posts 1–7 of 7 · Page 1 of 1
[HELP] Pointer help
It may be simple for u, but not for a beginner

Code:
int nombre = 8;
int *p1 = &nombre;
int **p2 = &p1;
Why does P2 gives the adress of P1? There are 2 *
why 2 *?
beside the p2 there are 2 *


int **p2 = &p1;
int nombre = 8;
int *p1 = &nombre; // a pointer
int **p2 = &p1; // a pointer of a pointer O.O
Because p2 points to the address of p1 which points to nombre.

p1 is equal to the address of nombre, so when you use the reference operator it gives you the value that nombre has.

And then when you put the address of p1 into p2 and you point to it, it gives you the value of p1 which is the address of nombre, so you use the reference operator once more and voila, you get nombre.
ok so the second * doesn't do anything? Its just to show that P1 is a pointer too?
1) int nombre = 8; // nombre is your pointer
2) int *p1 = &nombre; // p1 is your new pointer that takes the value from nombre pointer
3) int **p2 = &p1;;// p2 is your new pointer takes the value from the p1 pointer

2 and 3 are basicly the same thing just one points to another...
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us