0% found this document useful (0 votes)
25 views1 page

Reference Variables

Uploaded by

radhikaj500
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

Reference Variables

Uploaded by

radhikaj500
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Reference Variables in C++

A reference variable in C++ is an alias for an existing variable. It provides another


name to refer to the same memory location. This means that any changes made
through the reference variable will also be reflected in the original variable.

Declaration:

data_type &reference_name = variable_name;

Here:

 data_type: The data type of the variable being referenced.


 &: The reference operator, used to declare a reference variable.
 reference_name: The name of the reference variable.
 variable_name: The name of the variable being referenced.

Key Points:

1. Initialization: A reference variable must be initialized at the time of


declaration.
2. No Reassignment: Once a reference is initialized, it cannot be reassigned to
refer to another variable.
3. No Null References: A reference variable cannot be null.
4. Efficiency: References can be more efficient than pointers in certain
scenarios, especially when passing arguments to functions.

You might also like