A

Admin • 833K Points
Coach

Q. What is the output of the following C++ code?

Code:
#include <iostream>

using namespace std;

class calculate {
int x, y;

public:
void val(int, int);
int sum() {
return (x + y);
}
};
void calculate::val(int a, int b) {
x = a;
y = b;
}
int main() {
calculate calculate;
calculate.val(5, 10);
cout << "The sum = " << calculate.sum();
return 0;
}
  • (A) The sum = 5
  • (B) The sum = 10
  • (C) The sum = 15
  • (D) Error because calculate is used as class name and variable name in line 19.
  • Correct Answer - Option(C)
  • Views: 25
  • Filed under category C++
  • Hashtags:

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.