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 function initalizes variables in a class: a) Destructor b) Constitutor c) Constructor

782


Differentiate between a template class and class template in c++?

716


What is function overloading c++?

663


What are manipulators in c++ with example?

676


How do we balance an AVL Tree in C++?

731






What are pointer-to-members in C++? Give their syntax.

726


What is polymorphism and its type in c++?

661


What is the full name of logo?

692


What is vector pair in c++?

810


How come you find out if a linked-list is a cycle or not?

658


Is c++ the best programming language?

641


What are disadvantages of pointers?

660


Explain about Garbage Collector?

753


What is command line arguments in C++? What are its uses? Where we have to use this?

731


What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?

772