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

query about reference

Discussion in 'C++' started by imported_kishore, May 27, 2008.

  1. imported_kishore

    imported_kishore New Member

    Joined:
    May 26, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hi All,

    can any one explain what is the exact difference between reference and pointer.

    what is advavantage of using reference over pointer.

    I have gone through some articles and books.

    But I am not much clear about this concept.

    What i feel is we can do everything with a pointer what ever can be done by a reference. so why there is a reference conecept .

    If possible suggest me some good articles only on these topics.

    Thanks
     
  2. crow

    crow New Member

    Joined:
    Nov 12, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Macedonia
  3. Bibhas

    Bibhas New Member

    Joined:
    Apr 22, 2008
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Pointers (address) can be NULL. Client can calls your API with NULL as argument. So if you do not check NULL every time before using a pointer GPF(crash) may occur. But such problem doesn’t occur with reference.
     
  4. Mahesh.Shetye

    Mahesh.Shetye New Member

    Joined:
    Mar 22, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Pointers are pointing to some object but reference is nothing but the same object for which you have created that. In memory, you have different memory allocation for the object and pointer. But for reference, there is no seperate memory allocation. You can use arithmatic operations on pointer but not on reference (like you increment a pointer by one, it will point to next object).
     

Share This Page