+ 2
please can someone explain pointer further
for example what does int ***p stands for?
2 ответов
+ 3
int *p1 points to an integer variable.
int **p2 can points to p1
int ***p3 can points to p2
example:
int a=5;
int *p1 = &a;
int **p2 = &p1;
int ***p3 = &p2;
Note that pointer stores memory address. If you look that this way, it is not complicated. p3 stores the address of p2, ...., p1 stores the address of variable 'a'. p2 points to a pointer that point to 'a'. You should imagine memory as a grid, and the pointer as an arrow. The begin of the arrow is a square, and the end of the arrow is also a square. For instance, the beginning of p1 is a square which is the end of p2. The end of p1 is the variable 'a'.
To change the value of the variable 'a' with p3, you should go through p2 and p1.
***p = 6;
+ 1
thanks alot. well explained