What is the difference between Pointer and a Reference?
When you would use them?




Answers were Sorted based on User's Feedback



What is the difference between Pointer and a Reference? When you would use them?..

Answer / srihariraju

A reference just renames a memory location for the
reader/programmer. Its more like renaming a constant with
#define. The reference does not really 'contain' the
address, instead the comiler *could* just substitute the
address for the reference at the assembly code level.

A pointer is a variable (it 'must' have a memory location
of its own (barring odd compiler tricks)) that *can* be
used like a reference or it can point to nothing (NULL) (a
reference cannot do that) and a pointer can get new memory
from the os (new command) while a reference must 'point' to
existing memory.

Is This Answer Correct ?    14 Yes 0 No

What is the difference between Pointer and a Reference? When you would use them?..

Answer / man

Reference is alias of a variable i.e. a constant pointer
which reference to a variable and can not be NULL.
You can not can get the address of ref. They are used as a
variable.

Pointers are variale that hold address of variable and can
be NULL. And can point to any number of variable.

Is This Answer Correct ?    3 Yes 0 No

What is the difference between Pointer and a Reference? When you would use them?..

Answer / vinay bondade

A Pointer is not a condt pointer unless you define it in
that way,but a referrence on the contrary is a const
pointer by default and adding to this implementation it is
deferrenced automatically.

Is This Answer Correct ?    1 Yes 3 No




What is the difference between Pointer and a Reference? When you would use them?..

Answer / nav

pointer are variable and no need to be initilise,but
refrence is the rename of variable and must be
initilise.pointer also assign null value but reference not
assign null value.

Is This Answer Correct ?    1 Yes 3 No

Post New Answer



More C++ General Interview Questions

What are the total number of lines written by you in C/C++? What is the most complicated or valuable program written in C/C++?

2 Answers   Intel,


whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int i1; int i2; char *ptr; static int mem; };

5 Answers   Huawei,


What is the size of pointer ? Also size of pointer in 64 bit pointer

4 Answers  


let a,b,c be three integer numbers.write a c++ program with a function void rotate 1()such that a->b->c and c->a.

1 Answers  


Which uses less memory? a) struct astruct { int x; float y; int v; }; b) union aunion { int x; float v; }; c) char array[10];

4 Answers   Quark,






write a programme to get a character and thier ASCII value

0 Answers  


Write a program to swap 2 chars without using a third varable? char *s = "A"; char *p = "B";

7 Answers   CTS,


What is a constructor initializer list and when we use constructor initializer list?

3 Answers   TCS, Soft Info,


class base { public: int fun(int) {} }; class base2 { public: int fun(float) { } }; so here qustion is both function either function overloading or over riding;

4 Answers   Manhattan,


When to use Multiple Inheritance?

6 Answers  


how to swap two numbers with out using temp variable

12 Answers   TCS, Global eProcure,


Ask to write virtual base class code?

0 Answers   Satyam,






Categories