C++ References

Configurare noua (How To)

Situatie

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

Solutie

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

Tip solutie

Permanent

Voteaza

(19 din 44 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?