Archived

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

cow_in_the_well

& and * and all that jazz

Recommended Posts

void foo(int *number); recieves a pointer to an integer, while the other one recieves a reference to it. A pointer is holds the address of a variable, while a reference is an alias for the variable name. There is not much noticable diff. but they are diff.

*** Triality ***

Share this post


Link to post
Share on other sites
an important diff is that you cant really pass null to a reference so you dont have to check that it is a valid pointer.


JS
http://www.thepeel.com/void

Share this post


Link to post
Share on other sites
quote:
Original post by JS

an important diff is that you cant really pass null to a reference so you dont have to check that it is a valid pointer.


No, you can - and very easy:

foo( *(int*) NULL );

You just don''t have to worry about it in the function.

Share this post


Link to post
Share on other sites
The first is C''s way of manually constructing a call by reference, using a pointer. That is, when you call this function you will pass an address.

The second is C++''s reference parameter operator, you can call it without using any operator and can access it in the function without needing special operators, it will automatically obtain the address for you.

I''m not sure that is totally correct, but I think the idea is right.
I''m sure I''ll be corrected if null_pointer comes along

-Mezz

Share this post


Link to post
Share on other sites
Yep!
Those guys are perfectly right.
If you still don''t understand it, you should read a book about c++ (stroustroups if you''re a hard one), or alternatively search through the forums here; it was explained *soooo* many times...

pi~

*jazz... mmm... i like jazz...*

Share this post


Link to post
Share on other sites