71.8k views
3 votes
What is the output of the following program?

#include
using namespace std;

int getValue(int);

int main()
{
int x = 2;

cout << getValue(x) << endl;
return 0;
}

int getValue(int num)
{
return num + 5;
}

A) 5
B) 2
C) 7
D) "getValue(x)"

1 Answer

5 votes

Final answer:

The output of the program is 7.

Step-by-step explanation:

The output of the program is 7 (option C).

The program defines a function called getValue that takes an integer as a parameter and returns that integer plus 5. In the main function, a variable x is initialized with the value 2.

The getValue function is called with x as an argument, so the value passed to the function is 2. The function adds 5 to this value and returns the result, which is 7. This value is then printed using the cout statement and followed by a newline character.

User Donny Kurnia
by
8.2k points