GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Nov-2007, 04:36
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 157
dlp has a spectacular aura about

Functions: Passing pointers vs by reference


Hey All,

I was wondering something. Fundamentally, is there anything different between passing a pointer and passing something by reference? For example:

CPP / C++ / C Code:
void func_with_ptr( int * a )
{
    *a = 5;
}

void func_by_ref( int & a )
{
    a = 5;
}

I know, at least in this case, they are functionally the same. I was wondering what about behind the scenes? Does C++ basically just do a bunch of mojo that when compiled, references are properly replaced with their pointer equivalents?

I was also wondering what happens when you return something by reference? The easiest example is an overload for the << operator to an ostream.

CPP / C++ / C Code:
struct test
{
    int a;
    double b;
};

ostream & operator<<( ostream & out, const test & t)
{
    out << t.a << '\t' << t.b;
    return out;
}

When a reference is returned, is that an address ala a pointer?

Thanks.
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 11:13
gnu.linkonce undefined reference newbie06 C++ Forum 4 13-Mar-2007 10:53
Passing an object as a reference. What is wrong? _Y_ Java Forum 1 29-Aug-2006 12:58
Difficulty Passing Structure Data Elements Between Functions jdbrine C++ Forum 9 21-May-2006 13:03
[Tutorial] Pointers in C (Part II) Stack Overflow C Programming Language 0 27-Apr-2005 18:36

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:48.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.