Practice mode / C++ Which operation is used as Logical ‘AND’ A Option A: Operator-& B Option B: Operator-|| C Option C: Operator-&& D Option D: Operator + Correct answer C. Operator-&& Show answer Report a problem How we write and check questions
Question 01 / C++ Assuming standard headers and using namespace std, what does this C++ code print? struct A { A() { f(); } virtual void f() { cout << “A”; } }; struct B : A { void f() override { cout << “B”; } }; int main() { B b; b.f(); } A Option A: A B Option B: AB C Option C: B D Option D: BB Correct answer B. AB Show answer Open question
Question 02 / C++ What is wrong with the function int& getValue() { int local = 5; return local; }? A Option A: It returns a reference to a local variable that is destroyed when the function returns B Option B: References cannot be returned from functions C Option C: A function returning int& must be declared const D Option D: local must be declared static to compile at all Correct answer A. It returns a reference to a local variable that is destroyed when the function returns Show answer Open question
Question 03 / C++ Assuming standard headers and using namespace std, what does this C++ code print? auto p = make_shared<int>(7); auto q = p; { auto r = p; cout << p.use_count(); } cout << p.use_count(); A Option A: 21 B Option B: 32 C Option C: 11 D Option D: 33 Correct answer B. 32 Show answer Open question
Question 04 / C++ What is the type of the nullptr literal in C++? A Option A: void* B Option B: std::nullptr_t C Option C: int D Option D: long Correct answer B. std::nullptr_t Show answer Open question
Discussion