Stripped Pointers

Aman Rubey
3 min readMay 25, 2021

Basically, we will be seeing how different pointers are connected to each other in this code (pointers used are n,p and a double pointer z). You can open two windows side by side for the better readability of this article.

Line 23: I’ve created one int variable ‘a’ which has the value 5 in it.

Line 24: Pointer variable n stores the address of a ( &a means address of variable a). Initialization like int *n=a is wrong since pointers store the address and not int or any other value.

Line 25: This line means that the thing which is stored in ‘n’ (which is the address of the variable ‘a’) gets stored in pointer variable ‘p’.

Line 26: Skipping for later.

Line 27: Skipping these lines for now.

Line 28: Skipping these lines for now.

Line 29: Skip.

Line 30: Skip.

Line 31: Prints the value of a which is 5.

Line 32: Prints the value of &a which is the address of the variable ‘a’.

Line 33: As told in line 24, this will be printing the thing which is stored in n (that is the address of variable a). This is confirmed by the fact that result of line 32 and line 33 is same.

Line 34: Prints the address of the pointer variable n.

Line 35: We are dereferencing here, that is getting the value of the thing stored in that address. ( See, n has address of a, so it goes to a’s address and gives the value stored in that address which is 5). Hence the result *n=5.

Line 36: As told in Line 25, we should see the address of a and now it is confirmed that it is the case because in the output we can see that the result of “p=” is same as line 32 and line 33.

Line 37: Prints the address of the pointer variable p.

Now coming back to lines 26 to 30.

Line 26: It is the declaration of a double pointer variable ‘z’ . Double pointer is a pointer which stores the address of the other pointer.

Line 27: This step is to demonstrate that when printing just z it outputs some hexadecimal value which is not the address of pointer variable z ( I forgot to add an extra line where I should have displayed the value of &z before assignment).

Line 28: The initialization like int **z= n is not allowed( since n is not the address of a pointer variable and neither does it contain the address of a pointer variable), instead it accepts only the address of the “pointer”.

Line 29: Nothing just the address of the double pointe variable z.

Line 30: Now when we print out the value of z, it outputs what it has stored inside it which is the address of the pointer variable n. This is confirmed by the fact that the output of the line 34 and Line 30 is same.

--

--