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.
πŸ’¬ Discuss
βœ… Correct Answer: (C) The sum = 15

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
188
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Dharmendra Sir
Publisher
πŸ“ˆ
84%
Success Rate