Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8289365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:29:33+00:00 2026-06-08T12:29:33+00:00

Read a lot of differences between pointers & references . Here is a brief

  • 0

Read a lot of differences between pointers & references.

Here is a brief description of what i learned.

1. Memory is allocated when a pointer is defined. A reference however, is a name alias & hence no memory is allocated for it(Is it correct?).

2. Reference is bound to be initialized at the time of definition because, a reference is implemented with a constant pointer & hence cannot be made to point to the other object.
A pointer however, is not necessary to be initialized at the time of definition & hence can also be changed to point to some other object.

3. A reference automatically gets de-referenced. When you write cout << p;
It is automatically de-referenced by the compiler & treated as cout << *p; by the compiler.

Here, p is the reference.

  1. A reference to a reference is not possible.Whenever, you declare a reference to a reference, its actually the reference to the same variable.
    e.g.

    int i;    
    int &r1=i;    
    int &r2=r1; <-------------------2
    

Compiler interprets the statement 2 as:
int &r2=(*r1)
and (*r1) is nothing but the variable i itself.

A pointer to a pointer is however possible.

5. Array of pointer is possible while array of references is not possible(Why?).

6. Address of pointer is possible. Address of reference is not possible. It gives of the address of the variable.

7. There are situations where you are bound to use references.You cannot use pointers there.
Consider the below example:

A a=b+c;

Where a,b,c are objects of class A.
The operator ‘+’ is overloaded as follows:

const A& operator+(const A& o)
{
     return A(i+o.i);
}

See sample code here: http://ideone.com/Q0pE1

Here the reference in the argument list is used to save the memory footprints.
You cannot use pointer in the argument list as you are bound to pass the address of object in the operator function.
A a=&b + &c;
However, if pointer is used in the parameter list, then we will end up adding the addresses rather than object itself.

I want to know that is there any other point that i am missing?

When should one go for pointer & when for reference?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:29:34+00:00Added an answer on June 8, 2026 at 12:29 pm

    Memory is allocated when a pointer is defined. A reference however, is a name alias & hence no memory is allocated for it

    What do you mean by “memory is allocated?” If you mean a heap allocation, as with new or malloc or whatever, no:

    int val = 5;
    int *pVal = &val; //No dynamic memory allocation.
    

    A pointer has a size, in the same way that int has a size. But that’s different from an “allocation”.

    Reference is bound to be initialized at the time of definition because, a reference is implemented with a constant pointer & hence cannot be made to point to the other object.

    No, a reference is bound at initialization time because that’s how references work. They are references to objects. The language states that it is impossible for them to not be bound, and it is impossible for their binding to change later. Therefore, it is necessary that references are bound when they are initialized.

    How a compiler implements references is entirely irrelevant.

    A reference automatically gets de-referenced.

    No. There is nothing to de-reference. A reference is merely another name for an already existing object. That’s all.

    Array of pointer is possible while array of references is not possible(Why?).

    Because a reference has to be bound when it is initialized. And it’s not possible to give each member of an array a separate object to be bound to. Thus, you would need some step between the creation of the array and the binding of the reference. Which is not allowed.

    Address of pointer is possible. Address of reference is not possible. It gives of the address of the variable.

    A reference is another name for an already existing object. You can’t get the address of a name; you can only get the address of an object.

    There are situations where you are bound to use references.

    There’s nothing stopping you from overloading operator+ for pointers to the types:

    A operator+(const A *lhs, const A *rhs) {...}
    

    Of course, this is a non-member function.

    Oh, and as a bonus:

    const A& operator+(const A& o)
    {
         return A(i+o.i);
    }
    

    This is broken. You’re returning a const& to a temporary you create. You should be returning it by value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read a lot of articles about differences between message queue and shared memory.
I've read many discussions on the difference between references and pointers and when to
I read a lot, also here, but couldn't find a simple way to do
I have read a lot and bit confused that isolated storage and cache memory
What's the difference between an URI, URL and URN? I have read a lot
I read lot's of docs, tried everything and still can't understand why my template
I've read lot of articles saying, that Java EE is most popular enterprise solution
I got question about log4net is it working on IIS 7,5? I read lot
Iv read a lot of search results regarding how to deal with a JSON
I read a lot of different opinions on it, but is WinRT an actual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.