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

Visual c++, i want write visuaL c++ FOR MY ALGORITHM

i want write visuaL c++ FOR MY ALGORITHM

Pointers, When declaring a variable of data type pointer, use the * in fron...

When declaring a variable of data type pointer, use the * in front of the variable name. These variables hold a memory location (like B45CDF), not an actual value like 30 or A:

#padovan string in c , #padovan string in java   program in java /...

#padovan string in java   program in java // aakash , suraj , prem sasi kumar kamaraj college program 1 : package test.padovanstring; public class PadovanStrin

How to define a structure, How to Define a Structure? Structure declara...

How to Define a Structure? Structure declarations are rather more complicated than array declarations, ever since a structure must be defined in terms of its individual members

Explain the following object oriented methodologies, Question 1 Explain th...

Question 1 Explain the following Object Oriented Concepts with suitable examples for each Question 2 Explain the following Object Oriented Methodologies Question 3 Descr

#padovan string in c, #write a program that counts the number of occurances...

#write a program that counts the number of occurances of the string in the n-th padovan string p(n)

Padovan string, #question:-program to counts tha no of occurances of the st...

#question:-program to counts tha no of occurances of the string in the nth padovan string

Explain function templates, Function Templates Function templates give ...

Function Templates Function templates give you with the capability to write a one function that is a skeleton, or template, for a family of similar functions. In function ov

Answer, Write a program to find the area under the curve y = f(x) between 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.

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