- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
- C++ Advanced
- C++ Files and Streams
- C++ Exception Handling
- C++ Dynamic Memory
- C++ Namespaces
- C++ Templates
- C++ Preprocessor
- C++ Signal Handling
- C++ Multithreading
- C++ Web Programming
C++ Online Quiz
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.
Q 1 - What is the output of the following program?
#include<iostream> using namespace std; class abc { public: static int x; int i; abc() { i = ++x; } }; int abc::x; main() { abc m, n, p; cout<<m.x<<" "<<m.i<<endl; }
Answer : A
Explaination
The static member variable ‘x’ shares common memory among all the objects created for the class.
#include<iostream> using namespace std; class abc { public: static int x; int i; abc() { i = ++x; } }; int abc::x; main() { abc m, n, p; cout<<m.x<<" "<<m.i<<endl; }
Q 2 - Which of the following is not the keyword in C++?
Answer : C
Explaination
All the rest are valid keywords of C++.
Q 3 - The following operator can be used to calculate the value of one number raised to another.
Answer : D
Explaination
There is no such operator in C/C++.
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(); }
Answer : A
Explaination
The 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(); }
Q 5 - Objects created using new operator are stored in __ memory.
Answer : B
Explaination
new operator allocates memory dynamically know as Heap/free memory.
Q 6 - With respective to streams >> (operator) is called as
Answer : B
Explaination
It extracts the data from stream into variables.
Q 7 - i) Exception handling technically provides multi branching.
ii) Exception handling can be mimicked using ‘goto’ construct.
Answer : A
Explaination
goto just does the unconditional branching.
Q 8 - What is the output of the following program?
#include<iostream> using namespace std; main() { union abc { int x; char ch; } var; var.ch = 'A'; cout<<var.x; }
Answer : B
Explaination
65, as the union variables share common memory for all its elements, x gets ‘A’ whose ASCII value is 65 and is printed.
#include<iostream> using namespace std; main() { union abc { int x; char ch; } var; var.ch = 'A'; cout<<var.x; }
Q 9 - What is the output of the following program?
#include<iostream> using namespace std; int x = 5; int &f() { return x; } main() { f() = 10; cout<<x; }
Answer : D
Explaination
A function can return reference, hence it can appear on the left hand side of the assignment operator.
#include<iostream> using namespace std; int x = 5; int &f() { return x; } main() { f() = 10; cout<<x; }
Q 10 - What is the output of the following program?
#include<iostream> using namespace std; void main() { char *s = "C++"; cout<<s<<" "; s++; cout<<s<<" "; }
Answer : B
Explaination
After s++, s points the string “++”.
#include<iostream> using namespace std; void main() { char *s = "C++"; cout<<s<<" "; s++; cout<<s<<" "; }
To Continue Learning Please Login
Login with Google