... // function prototype (reference pass)
 8
 9   int main() {
10      int x{2}; // value to square using squareByValue
11      int z{4}; // value to square using squareByReference
12
13      // demonstrate squareByValue
14      cout << "x = " << x << " before squareByValue\n";
15      cout << "Value returned by squareByValue: "
16         << squareByValue(x) << endl;
17      cout << "x = " << x << " after squareByValue\n" << endl;
18
19      // demonstrate squareByReference
20      cout << "z = " << z << " before squareByReference" << endl;
21      squareByReference(z);
22      cout << "z = " << z << " after squareByReference" << endl;
23   }
24
25   // squareByValue multiplies number by itself, stores the
26   // result in number and returns the new value of number
27   int squareByValue(int number) {                              
28      return

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.