Differences between a pointer and a reference, C/C++ Programming

Assignment Help:

Differences between a pointer and a reference

1.  A reference must always point to some object where as this restriction is not imposed on a pointer.

e.g.

int *pi = 0;           // pointer can point to no object.

const int &ri = 0      would be converted as ,

int temp = 0;

const int &ri = temp;

2. The assignment of one references with other changes the object being referenced and not the reference itself.

e.g.

 int ival1 = 1000, ival2 = 2000;

 int *pi1 = &ival1, *pi2 = &ival2;

 int &ri1 = ival1, &ri2 = ival2;

pi1 = pi2;

 

  • ival1 remains unchanged but pi1 and pi2 now address the same object ival2.

ri1 = ri2;

  • ival1 becomes 2000. ri1 and ri2 still refer to ival1 and ival2 respectively.

 


Related Discussions:- Differences between a pointer and a reference

Minimum shelf, At a shop of marbles, packs of marbles are prepared. Packets...

At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes

College, #question.College life is tough. Eating pizza for every meal is h...

#question.College life is tough. Eating pizza for every meal is hitting you hard. You are looking at working out to stay healthy. You found a web site that tells you how many ca

Functions, differentiate between inbuilt and user defined functions

differentiate between inbuilt and user defined functions

Tower of hanoi, application problem of tower of hanoi

application problem of tower of hanoi

Compiler designin liliting instruction, Ravi is a newbie to the programming...

Ravi is a newbie to the programming and while learning the programming language he came to know the following rules:

Program that implements inference given a bayesian network, In this problem...

In this problem, you will write a program that implements two algorithms for performing exact inference given a Bayesian network, namely, enumeration and variable elimination. Your

Determine the types of container class, Determine the types of Container cl...

Determine the types of Container class Container class can be of 2 types: - Heterogeneous container - Here container class comprise a group of mixed objects - Homogeneou

Area under curve, Write a program to find the area under the curve y = f(x)...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b.   #include float start_poin

Develop a biomedical imaging project, Develop a biomedical imaging project ...

Develop a biomedical imaging project Project Description: This is a biomedical imaging project. Skills required are C++ Programming, Cocoa, Mac OS, Objective C

Area under curve, Write a program to find the area under the curve y = f(x)...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b.     #include float start

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd