Following quiz provides Multiple Choice Questions (MCQs) related to C++ Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.
Answer : B ExplainationIf a member/s appear in the class with following no access specifier, the default is private.
Answer : D ExplainationOverloaded assignment operator does the job similar to copy constructor and is required to be overloaded as member function of the class.
Answer : D Explainationmutable is storage specifier introduced in C++ which is not available in C. A class member declared with mutable is modifiable though the object is constant.
Q 4 - What is the output of the following program?
#include<iostream> using namespace std; class Base { public: void f() { cout<<"Base\n"; } }; class Derived:public Base { public: void f() { cout<<"Derived\n"; } }; main() { Base *p = new Derived(); p->f(); }
A - Base
B - Derived
C - Compile error
D - None of the above.
Answer : A ExplainationThe method f() is not overridden therefore as per the pointer type respective method is called.
#include<iostream> using namespace std; class Base { public: void f() { cout<<"Base\n"; } }; class Derived:public Base { public: void f() { cout<<"Derived\n"; } }; main() { Base *p = new Derived(); p->f(); }Answer : C Explaination
A constructor cant be overridden.
Answer : D ExplainationCompile error - constant variable cannot be modified.
#include<iostream> using namespace std; main() { const int a = 5; a++; cout<<a; }
Q 8 - What is the size of the following union definition?
#include<iostream> using namespace std; main() { union abc { char a, b, c, d, e, f, g, h; int i; }; cout<<sizeof(abc); }
A - 1
B - 2
C - 4
D - 8
Answer : C Explainationunion size is biggest element size of it. All the elements of the union share common memory.
#include<iostream> using namespace std; main() { union abc { char a, b, c, d, e, f, g, h; int i; }; cout<<sizeof(abc); }Answer : C Explaination
option (a) & (b) are valid. There is no such syntax or provision as in option (c).
Answer : D Explainations refers to a constant address and cannot be incremented.
#include<iostream> using namespace std; void main() { char s[] = "C++"; cout<<s<<" "; s++; cout<<s<<" "; }
cpp_questions_answers.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4