What is the difference between reference type and pointers.

Answers were Sorted based on User's Feedback



What is the difference between reference type and pointers...

Answer / manoj kumar kar

Difference 1>
Reference must point to valid objects at the time of
declaration where pointer need not point to valid objects
at the time of declaration means
int nvalue=5;
int &rnvalue; //This is invalid.
int &rnvalue=nvalue; //This is valid.

But
int *rnvalue; //This is valid.
rnvalue=&nvalue;
Difference 2>
Pointer is a variable which holds the address of another
variable.
But Reference is another name of the same variable.

Is This Answer Correct ?    18 Yes 1 No

What is the difference between reference type and pointers...

Answer / k govind

In addition to the previous answer given in Answer #1,
namely References must point to valid objects at the time
of declaration, references also has the following
limitation.

Once a reference is assigned, there's no way you can modify
the reference. However for a pointer type, variable
assignment is legal.

e.g.,

int i, j;

int *pi, *pj;

pi = &i; // pointer to i
pj = &j; // pointer to j

int &k = i; // reference to i

pi = pj; // pi no longer points to i, instead
// it is now pointing to j
k = j; // The reference k is still with i, it is only
// the value of i that is now modified. i is
// assigned the value of j

Is This Answer Correct ?    3 Yes 0 No

What is the difference between reference type and pointers...

Answer / p.madhupriya

pointer is a variable that points to address of another
variable .
reference is variable that points to address of that
variable only.

Is This Answer Correct ?    2 Yes 0 No

What is the difference between reference type and pointers...

Answer / snigdhadeb

REFERENCE:-
#include<iostream.h>

int main()
{
int a=3;
/*A reference variable must be initialized at the time
of it's declaration*/

int &ra=a;
int y=6;
/*int &ry;
ry=y; // not allowed */

int &ry=y;
/* It should be noted that a reference variable dose not
creat a copy so it dose not takes any additional memory
space. Thus memory space is conserved*/

/* It has notational clearness*/

int z=ra * ry;
/* To access the value of a variable thought it's
reference no additional symbol is required, i.e.
dereference is not required*/

return 0;
}

POINTER:-

include<iostream.h>

int main()
{
int a=3;
/* A pointer variable may be declared without
initialization*/

int *pt;
/* A pointer variable may be intialized later on*/

pa=&a;
/* Also a pointer variable may be intialized at the time
of int's declaration*/

int b=5;
int *pb=&b;
/* It is also observed that each pointer variable
required it's own storage, so memory is not conserved*/

/* it's dose not have notational clearness*/

int c=*pa * *pb;
/* Access the value of a variable through it's pointer
requires value at (*) symbol, i.e. dereference is required*/

return 0;
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

Does there exist any other function which can be used to convert an integer or a float to a string?

0 Answers  


List the merits and demerits of declaring a nested class in C++?

0 Answers  


Is c++ low level?

0 Answers  


Write a Program to find the largest of 4 no using macros.

0 Answers  


To which numbering system can the binary number 1101100100111100 be easily converted to?

0 Answers  






Write about the various sections of the executable image?

0 Answers  


Explain the benefits of proper inheritance.

0 Answers  


pls help.. paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1.. create a program that will count all the paper bills in the number being input.. example: enter a number: 3886 there is/are: 3 ->1000 1 ->500 3 ->100 1 ->50 1 ->20 1 ->10 1 ->5 1 ->1 example2: enter a number: 728 there is/are: 0 ->1000 1 ->500 2 ->100 0 ->50 1 ->20 0 ->10 1 ->5 3 ->1

4 Answers  


What is #include ctype h in c++?

0 Answers  


Will c++ be replaced?

0 Answers  


Can user-defined object be declared as static data member of another class?

0 Answers  


What is boyce codd normal form in c++?

0 Answers  


Categories