Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: I thought I...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 5 Topic 43646 of 48417
Post > Topic >>

Re: I thought I understood pointers.

by Kai-Uwe Bux <jkherciueh@[EMAIL PROTECTED] > Mar 3, 2008 at 09:45 AM

noagbodjivictor@[EMAIL PROTECTED]
 wrote:

> Hi all,
> 
> I thought I knew how pointers work, but then I'm struggling with a
> code, well I happen to have written last semester in my data structure
> class. Why do we pass the pointer to the node of a binary tree by
> reference? Isn't a pointer supposed to hold the address of an object
> in memory?
> 
> Take this for example:
> ItemType findMax(TreeNode* & tree) {
>   while(tree->right != NULL)
>     tree = tree->right;
>   return tree->info;
> }
> 
> Why are we are passing the pointer tree by reference here? Don't be
> too harsh, I just happen to have forgotten a little bit...

The code seems to search for the right-most leaf in a tree. What passing
the
parameter tree by reference does for you is that the function changes the
variable so that it will point to the right-most leaf after the call.


Best

Kai-Uwe Bux
 




 5 Posts in Topic:
I thought I understood pointers.
"noagbodjivictor@[EM  2008-03-03 06:30:14 
Re: I thought I understood pointers.
Kai-Uwe Bux <jkherciue  2008-03-03 09:45:49 
Re: I thought I understood pointers.
"Eric Pruneau"   2008-03-03 10:05:42 
Re: I thought I understood pointers.
"noagbodjivictor@[EM  2008-03-03 07:29:16 
Re: I thought I understood pointers.
kasthurirangan.balaji@[EM  2008-03-03 21:31:13 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 10:24:05 CST 2008.