1. The reference is an alias. The reference is just another name of the object.
2.
Code:
- Int ivals = 1024;
- Int & ref = ival;
3. Define multiple references
Code:
- Int ival = 1024; iival = 1025;
- Int & ref1 = ival, & ref2 = iival;
4. A const reference is a reference to a const object.
Code:
- Const int ival = 1024;
- Const Int & ref = ival;
- Int & ref2 = ival; // Error
5.
Code:
- // Compilation failed
- Float ivalue = 3.14;
- Int & Reff = ivalue;
- // Compilation successful
- Const float ivalue = 3.14;
- Const Int & Reff = ivalue;
- Different types of conditions.
================================= 4.18 day review updates ======================== ======================================
Code:
- // Compilation successful
- Const float ivalue = 3.14;
- Const Int & Reff = ivalue;
Compiler:
Const int temp = ivalue;
Const Int & Reff = temp;
Ivalue is not modified
A const reference can be bound to a different but associated type object or to the right value.