What is the difference between reference type and pointers.

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is late binding c++?

712


Can a program run without main in c++?

805


What do you understand by a pure virtual member function?

756


What is data hiding c++?

764


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

794






Describe the process of creation and destruction of a derived class object?

844


How is modularity introduced in C++?

923


Which operations are permitted on pointers?

736


How do you declare A pointer to function which receives an int pointer and returns a float pointer

873


What is the this pointer?

806


What are friend functions in C++?

795


Explain about vectors in c ++?

771


What is virtual methods?

862


How long will it take to learn programming?

773


what kind of projects are suitable for c and c++

806