1
Loading subject content…
Loading subject content…
Loading practice questions…
What will be the output of the program?
#include <iostream>
using namespace std;
class C {
public:
static int n;
C() { n += 2; }
};
int C::n = 1;
int main() {
C a, b;
cout << C::n << endl;
return 0;
}What will be the output of the program?
#include <iostream>
using namespace std;
class P {
int v;
public:
P(int x) : v(x) {}
friend int peek(const P &p);
};
int peek(const P &p) { return p.v; }
int main() { cout << peek(P(42)) << endl; return 0; }What will be the output of the program?
#include <iostream>
using namespace std;
class A {
public:
int x = 1;
A& add(int n) { x += n; return *this; }
};
int main() {
A a;
a.add(2).add(3);
cout << a.x << endl;
return 0;
}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;
}