Reference and Pointer

Discussion in 'C++' started by kaustubh, Aug 15, 2007.

Thread Status:
Not open for further replies.
  1. kaustubh

    kaustubh New Member

    Joined:
    Aug 13, 2007
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    0
    Reference is the other name given to the same variable. Pointer is new variable created which can contain address of another variable.

    Try an experiment

    Code:
    # include<iostream>
    using namespace std;
    int main()
    {
    
    int i = 90; // variable
    int &j = i;  // reference 
    int *P;   //  pointer
    P =&i;
    
    cout<<endl<< "address of variable :i" <<&i;
    
    cout<< endl << "address of reference: j" <<&j;
    cout<<endl<<"address of pointer : P"<<&P;
    return 0;
    }
    OUTPUT:
     address of variable i: 0012FEDC
    address of reference j: 0012FEDC
    address of pointer p: 0012FEE0
    
    so you see the address of i and reference j is same , address of pointer P is different.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice