References in C++
If you want to create an alternate name for a variable, then this is option you have. You can access the variable as reference. How to create a Reference? It uses ‘&’ symbol to create the reference. Syntax: ‘data_type &ref_name= variable;’ Eg: ‘int &ref = a;’ Let us create a C++ program to use the reference. This program starts by including built-in header file <iostream>. ‘main()’ function creates two variable ‘a’ and ‘reference’. Get the ‘a’ value from the user. Assign it to reference. Get the value two more time and assign it to reference. Print the value. Program: #include <iostream> using namespace std; int main() { int a; cout<<"Enter the value:"<<endl; cin>>a; //create the reference value and assign the variable int &reference = a; //let us change the...