Jump to content

C++ Lessons : 20. References


quix
 Share

Recommended Posts

  • Manager

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

 

Hi,

DM me ONLY if you have problems on my uploads!

With love, quix!

Link to comment
Share on other sites

  • quix locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...