Jump to content
  • Advertisement

Archived

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

milkywayman

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!