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 pointer -to-members in C++? Give their syntax?

593


Who discovered c++?

556


What is implicit conversion/coercion in c++?

644


Difference between strdup and strcpy?

642


How does atoi function work?

618






What is the difference between method overloading and method overriding in c++?

556


If you push the numbers (in order) 1, 3, and 5 onto a stack, which pops out first a) 1 b) 5 c) 3

830


What are the extraction and insertion operators in c++? Explain with examples.

635


What is the full form of stl in c++?

669


What is the benefit of learning c++?

545


What is a float in c++?

539


What are the characteristics of friend functions?

559


Can a class be static in c++?

561


What are the differences between java and c++?

526


What is #include math h in c++?

565