204k views
0 votes
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; }

User Lei
by
6.4k points

1 Answer

0 votes

Answer:

The output of the given C++ language code is as follows:

Output:

5 10

Step-by-step 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.

User Aaron Franke
by
6.8k points