Reference parameter in C++
Level 392 keystrokes
doubleValue takes its parameter by reference (int&), so changing x inside the function changes the caller's num: 5 becomes 10.
C++ code
// int& makes x a reference: another name for the variable passed in, not a copy1void doubleValue(int& x) { // Doubles the value; this writes directly to the caller's variable2 x = x * 2;3}4 5int num = 5;// Passes num by reference; after the call num is 106doubleValue(num);// Prints 107cout << num << endl;Output
10
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C++ code and how often they appear.
;× 4<× 4(× 2)× 2=× 2{× 1}× 1*× 1&× 1