A
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;
}
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;
}
- Correct Answer - Option(C)
- Views: 25
- Filed under category C++
- Hashtags:
Discusssion
Login to discuss.