What will be the output of the following C++ code?

int calculate()
{
    return 25;
}

int main()
{
    int x = calculate();
    cout << x;
}
                        

Options

  • B. 25
  • C. Garbage value
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. 25

Detailed Explanation

Answer: (B) 25

The function calculate() has return type int and returns the value 25.

In main(), the returned value is assigned to x:

int x = calculate();

Therefore, x contains 25 and the program prints 25.