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 istream and ostream in c++?

599


Which sort does c++ use?

582


What is c++ redistributable?

626


Of the numbers 12 23 9 28 which would be at the top of a properly implemented maxheap a) 28 b) 9 c) Any of them could be

933


What are the rules about using an underscore in a c++ identifier?

636






Write about an iterator class?

615


Describe linkages and types of linkages?

571


What is guard code in c++?

644


Explain the difference between c & c++?

593


Describe the syntax of single inheritance in C++?

651


What is the difference between #import and #include?

555


Define a nested class.

615


What does the linker do?

597


How do you compile the source code with your compiler?

620


When we use Abstract Class and when we use Interface?where we will implement in real time?

1671