#### Archived

This topic is now archived and is closed to further replies.

# Multiple indirection

This topic is 5564 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi ppl acctually i seem to be confused, i have learned 2 ways to have point to pointer, or multiple indirection, i need to know how are they different, cause the book i am reading only show 1 way, but i learned the other by my self here is the source code for both ways #include main() { // first way int x = 50; int *ptrx = &x; int *ptr2 = ptrx; printf("x = %d\n", *ptr2); //second way int y = 60; int *ptry = &y; // 1 level indirection int **ptr_to_ptry = &ptry; // 2 level indirection printf("y = %d\n",**ptr_to_ptry); the first way uses int x, where else the second way uses int y.. any help will be appreciated. thanks a lot

##### Share on other sites
the first way is not multiple indirection.
int *ptrx = &x;
int *ptr2 = ptrx;

is the equivalent of doing:
int *ptrx = &x ;
int *ptr2 = &x ;

only the second method is actually having a pointer to a pointer.

##### Share on other sites
ok, i get it, the first way is just another method of pointing to the same momory address,

where else the second method creates a pointer which points to another pointer.....and this is called multiple indirection...

thanks lot.man.

##### Share on other sites
quote:
Original post by milkywayman
ok, i get it, the first way is just another method of pointing to the same momory address,

where else the second method creates a pointer which points to another pointer.....and this is called multiple indirection...

thanks lot.man.

exactly right. no problem.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013741
×