Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

C++ References


Creating References

A reference variable is a "reference" to an existing variable, and it is created with the & operator:

string food = "Pizza";  // food variable
string &meal = food;    // reference to food

Now, we can use either the variable name food or the reference name meal to refer to the food variable:

Example

string food = "Pizza";
string &meal = food;

cout << food << "\n";  // Outputs Pizza
cout << meal << "\n";  // Outputs Pizza
Run example »