1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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,293
    Likes Received:
    365
    Trophy Points:
    83
Thread Status:
Not open for further replies.

Share This Page