🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to C++ Notes
Topic #66

C++ References


Creating References

A reference variable is an alias for an existing variable. It is created using the & operator:

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

Now, you can use either food or meal to refer to the same value:

Example

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

cout << food << "\n";
// Outputs Pizza
cout << meal << "\n";  //
Outputs Pizza

Note: Both food and meal refer to the same memory location. Changing one affects the other.


Updating Through References

If you change the value of a reference variable, the original variable will also change (and vice versa), because they both refer to the same memory location:

Example

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

meal = "Burger"; // changes both meal and food

cout <<
food << "\n"; // Outputs Burger
cout << meal << "\n"; // Outputs Burger

Want to go beyond the notes?

Join CodingNow 2.0's C++ course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

C++ References – FAQs

Quick answers about learning C++ References in C++.

This free note from CodingNow 2.0 explains C++ References in C++ — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every C++ topic on CodingNow 2.0, including C++ References, is 100% free with no signup required.
With focused practice, most students grasp C++ References in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now