Home / Programming MCQs / C++ MCQs / Question

D

Dharmendra Sir • 3.53K Points
Extraordinary

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

Code:
#include <iostream>
using namespace std;
class MyClass
{
  int var;
 
   public:
  int write(int i) const {
    var = i;
  }
  int read() const {
    return var;
  }
};
int main(int argc, char const *argv[])
{
  MyClass obj;
  obj.write(2);
  cout << obj.read();
}
(A) 2
(B) 3
(C) Compilation error
(D) None of the above

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.