Reference variables

Reference variable behave similar to both, a value variable and a pointer variable. Value variable are used to hold some numeric values, pointer variable are used to hold the address of some other variable. In programme code reference variable is used similar to that of a value variable but has an action of a pointer variable." Reference variable benefits from the simplicity of the value variable and power of pointer variable". It does provide the flexibility supported by the pointer variable, unlike pointer when a reference is bound to a variable, then its binding cannot be changed. All the accesses made to the reference variable as same as to the access to which it is bound. The general format of declaring reference variable is:

 

Data type and reference variable + value variable

Where data type can be standard or user defined type:

Like Int, char, float etc.

& reference operator

The reference variable must be initialized to same variable only at the point of its declaration. Initialization of reference variable following its declaration sources compilation error.

 




 

   Related Questions in Programming Languages

©TutorsGlobe All rights reserved 2022-2023.