What is the output of the following program segment? int main() { int num = 5; cout << num <<" "; change(num); cout << num << endl; return 0; } void change (int &num) { num = 10; }
The output of the given C++ language code is as follows:
Output:
5 10
Explanation:
Description of the given C++ language code as follows:
In this code, the main method is defined inside the main method an integer variable num is declared that contains a value that is "5".
In this method first, a variable value is printed then a function that is "change" is called then we print function value.
In the last, a change method is defined, which contains an integer variable "num" in its parameter, and inside a function num variable another value is defined, that is 10, that's why the first 5 and then 10 value is printed.