Pointer pointer pointer

I worked with c pointers and could not explain the following code:

int main() { int i = -3; int *ptr; int **ptr2; int ***ptr3; ptr = &i; ptr2 = &ptr; ptr3 = &ptr2; printf("ptr = %p\n",(void *)ptr); printf("&ptr = %p\n",(void *)&ptr); printAddr(&ptr); printAddr2(&ptr2); printAddr3(&ptr3); return 0; } void printAddr(int **num) { printf("address of int ** = %p\n", (void *)&num); } void printAddr2(int ***num) { printf("address of int *** = %p\n", (void *)&num); } void printAddr3(int ****num) { printf("address of int **** = %p\n", (void *)&num); } 

The output is as follows:

 ptr = 0xbf9d64a0 &ptr = 0xbf9d64a4 address of int ** = 0xbf9d6490 address of int *** = 0xbf9d6490 address of int **** = 0xbf9d6490 

My doubt is why you should go to (address(int)) == address(address(address(int))) ?

Thanks so much for the clarification.

I found this question to matter:

Recursive Pointers

But the author explicitly appoints them equal.

+4
source share
1 answer
 void printAddr(int **num) { printf("address of int ** = %p\n",(void *)&num); } 

This prints the address of the copy of the passed value that the function received. Most likely, all of them will be placed in one place on the stack, since all these functions take only one argument, and between calls does not occur.

If you want to see the addresses of pointers in main , you must either print them directly in main , or have a function

 void printAddress(void* p) { printf("%p\n", p); } 

and call it with

 printAddress(&ptr3); 

and etc.

+5
source

All Articles