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

Scrape a site and save as csv, Scrape a site and save as csv Project Des...

Scrape a site and save as csv Project Description: I want a programmer to create scraping software. I'll want every page scraped of name, job title, company, and url. There a

Decodethecode, how to decode the numerals to string..

how to decode the numerals to string..

Password Validation Prgram in C++, Create a .cpp program that verifies the ...

Create a .cpp program that verifies the strength of a password that a user is entering is strong (complex/secure) enough. In the main area of the program, prompt the user to enter

Padovan string, A Padovan string P(n) for a natural number n is defined as:...

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concate

Calculate the area and circumference of a circle , Write a program which in...

Write a program which incorporates a function named compute and which is used to calculate the area and circumference of a circle. Use the main function for inputs and outputs.

Statistical and Numerical methods using C++–, An experiment succeeds twice ...

An experiment succeeds twice as often as it fails. Find the chance that in the next six trials there will be at least four successes.

Super ascii, program to convert string from super ascii string with minimum...

program to convert string from super ascii string with minimum cost

What is the difference between structure and class, What is the difference ...

What is the difference between structure and class? - Members of structures are public while those of a class are private. - Classes provide data hiding while structures don

Binary search tree and graph, Important Note: No course works, which have b...

Important Note: No course works, which have been submitted via hard copies or emails, will be accepted a short essay below edited in a document (word, other) files with

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