What will be the output of the following C++ code?

#include <iostream> using namespace std; class Point { int x, y; public: Point(int i = 0, int j =0) { x = i; y = j; } int getX() const { return x; } int getY() {return y;} }; int main() { const Point t; cout << t.getX() << ” “; cout << t.gety(); return … Read more

What will be the output of the following C++ code?

#include <iostream> class Test { public: void fun(); }; static void Test::fun() { std::cout<<“fun() is static”; } int main() { Test::fun(); return 0; } a) fun() is static b) Compile-time Error c) Run-time Error d) Nothing is printed

What will be the output of the following C++ code?

#include<iostream> using namespace std; class Test { private: static int count; public: Test& fun(); }; int Test::count = 0; Test& Test::fun() { Test::count++; cout << Test::count << ” “; return *this; } int main() { Test t; t.fun().fun().fun().fun(); return 0; } a) 4 4 4 4 b) 1 2 3 4 c) 1 1 1 … Read more

What will be the output of the following C++ code?

#include <iostream> using namespace std; class A { private: int x; public: A(int _x) { x = _x; } int get() { return x; } }; class B { static A a; public: static int get() { return a.get(); } }; int main(void) { B b; cout << b.get(); return 0; } a) Garbage value … Read more

What will be the output of the following C++ code?

#include <iostream> using namespace std; class Player { private: int id; static int next_id; public: int getID() { return id; } Player() { id = next_id++; } }; int Player::next_id = 1; int main() { Player p1; Player p2; Player p3; cout << p1.getID() << ” “; cout << p2.getID() << ” “; cout << … Read more

What will be the output of the following C++ code?

#include <iostream> using namespace std; class Test { static int x; public: Test() { x++; } static int getX() {return x;} }; int Test::x = 0; int main() { cout << Test::getX() << ” “; Test t[5]; cout << Test::getX(); } a) 0 0 b) 5 0 c) 0 5 d) 5 5