Explain reference types, C/C++ Programming

Assignment Help:

Reference Types

The symbol "&" is interpreted as an address operator as well as AND operator. This operator is also used to declare a "reference variable". A reference is referred to an alias, serves as an alternative name for the object.

e.g.

                int ival  = 1024;

                int &rval  =  ival;  // rval is reference to ival

  • A reference variable should be initialized at time of declaration itself.

e.g.

                int &iref;              // wrong

                int &iref  =  ival  //o.k.

  • Once a reference has been made to a variable, it cannot be altered to refer to another variable.

e.g.

void main()

{

                  int num1  =  10, num2  =  200;

                  int &ref  =  num1;

  cout<< num1 << num2 << ref ;                //10,200,10;

  ref  =  num2;

  cout << num1 << num2 << ref ;               //200,200,200

                      }

It changes the contents of the original variable, which is not the desired action.

 


Related Discussions:- Explain reference types

Diploma in IT, Function fact explain how the process of recursion works in ...

Function fact explain how the process of recursion works in C++.In your answer assume that the function is called to calculate the factorial of 6?

Assignment, Develop a C++ program that uses a while to determine the gross ...

Develop a C++ program that uses a while to determine the gross pay (in Dollars) for each of several employees. The company pays “straight-time” for the first 40 hours worked by ea

Define procedure that take argument or return integral value, Simpson's Rul...

Simpson's Rule is a more accurate method of numerical integration than the method described in class. Using Simpson's Rule, the integral of a function f between a and b is approxim

Compute the average of five numbers, Step 1 Define the program headers and ...

Step 1 Define the program headers and the variables      #include   #include   #include   #include void main()   {       char prompt;     float a,b,c,d,e;     floa

Array, If an array holds integer, each of which is four bytes long, how man...

If an array holds integer, each of which is four bytes long, how many bytes from the base location of the array is the location of the fifth element?

Described container class?explain types of container class, A container cla...

A container class is a class which is used to hold objects in external storage and memory. A container class work as a generic holder. A container class contains a predefined behav

I need poker room auto seat program, Project Description: I want a scrip...

Project Description: I want a script for an online poker site. It needs to be scanning all the required tables and when the table meets certain criteria it should take a seat at

Socket Programming, Need someone to look over my assignment for correctness...

Need someone to look over my assignment for correctness and make any necessary changes.

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