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

Function declarations and function definitions in cpp, FUNCTIONS It refe...

FUNCTIONS It refers to a subprogram that is meant to do a certain task. It is basically used to execute a set of operations and return information to the main or calling functio

Program of binary tree, Program of Binary tree: Btree::Btree(int O) : ...

Program of Binary tree: Btree::Btree(int O) : itemsInContainer(0) {     finishInit(O); }   Btree::~Btree(void) {     if( root != 0 )         delete roo

Introduction to C language, Design and implement a library system that does...

Design and implement a library system that does the following: ? Takes details of a student/library users: first name, last name, other names, user ID number, and nationality. Th

Sequence for DMA controller, Write a sequence of instructions that transfer...

Write a sequence of instructions that transfers data from memory to an external I/O device by using channel 3 of the 8237 DMA controller. Transfer from 20000H-20FFFH.

Rules of operator overloading, Rules of Operator Overloading It is ...

Rules of Operator Overloading It is a function defined to an operator with new term or meaning. It cannot produce new operator. It cannot modified the meaning of th

I need whatsapp software in my website, I need whatsapp software in my webs...

I need whatsapp software in my website Project Description: i need whatsapp software in my website same this whatsapp if anyone can make to me this in my website Skills

Compute the net pay for employees - c program, Write a C# program to comput...

Write a C# program to compute the Net Pay for employees. The program is to have a Main method and two user-defined methods. The Main method is to input the employee's name (string)

Does improper inheritance have potential to wreck a project, Does improper ...

Does improper inheritance have a potential to wreck a project? Many projects meet a dead end due to bad inheritance. Hence it certainly has potential to wreck a project. Sma

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