LogiQuest
Back to Objects and Classes
12

What will be the output of the program?

#include <iostream>
using namespace std;
class P {
    mutable int reads = 0;
    int v = 5;
public:
    int get() const { ++reads; return v; }
    int count() const { return reads; }
};
int main() {
    P p;
    p.get(); p.get();
    cout << p.count() << endl;
    return 0;
}
Hard

Discussion (0)

  • No discussion yet. Ask a doubt or share a shortcut.

Log in to join the discussion.