1

Possible Duplicate:
Difference between pointer variable and reference variable in C++

This is a continuation of this question

Is a reference variable just another name of const pointer variable? If they are different what is the difference between a variable declared as a reference variable and a variable declared as a const pointer variable?

Community
  • 1
  • 1
Sulla
  • 7,631
  • 9
  • 45
  • 71
  • Unless you really meant to ask the difference between a pointer and a const pointer this is a duplicate of the question that you linked to. – CB Bailey Dec 02 '10 at 07:42
  • This has already been answered in the same question you are referring to. From the first answer, all points hold besides the *can be reassigned*. Possible duplicate of [Difference between pointer variable and reference variable in C++](http://stackoverflow.com/questions/57483/difference-between-pointer-variable-and-reference-variable-in-c) – David Rodríguez - dribeas Dec 02 '10 at 08:45

3 Answers3

3

Just for fun:) A reference can not be NULL but a const pointer can be.

Chubsdad
  • 24,777
  • 4
  • 73
  • 129
1

OK. The problem is that there is no such thing like reference variable. Reference is not a variable at all. It is not an object. It actually has no size at all. It is just alternative name of the original object.

Check this:

struct A
{
   int i[5];
};

int main()
{
   std::cout << (sizeof(A&) == sizeof(A)) << std::endl;
   std::cout << (typeid(A&) == typeid(A)) << std::endl;
   return 0;
}

A& has the same size as A
A& has the same type as A
Stas
  • 11,571
  • 9
  • 40
  • 58
  • Correct for C++03, but [C++0x introduces the notion of reference variables](http://stackoverflow.com/questions/2908834/). – fredoverflow Dec 02 '10 at 11:51
0

Is a reference variable just another name of const pointer variable?

No.

If they are different what is the difference between a variable declared as a reference variable and a variable declared as a const pointer variable?

They are completely different things, and there is not enough room to explain everything you need to know here. Read this. Actually, read the entire FAQ. You'll learn a lot.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153