- 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++ Mock Test
This section presents you various set of Mock Tests related to C++ Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.
C++ Mock Test II
Q 1 - What is the output of the following program?
#include<iostream> using namespace std; main() { int i = 1, j = 2, k = 3, r; r = (i, j, k); cout<<r<<endl; }
Answer : C
Explaination
Comma is called as the separator operator and the associativity is from left to right. Therefore ‘k’ is the expressions resultant.
#include<iostream> using namespace std; main() { int i = 1, j = 2, k = 3, r; r = (i, j, k); cout<<r<<endl; }
Q 2 - In the following program f() is overloaded.
void f(int x) { } void f(signed x) { } main() { }
Answer : B
Explaination
No, as both the functions signature is same.
Q 3 - In the following program f() is overloaded.
void f(int x) { } int f(signed x) { return 1; } main() { }
Answer : B
Explaination
No, as both the functions arguments is same and compiler ignores return type to consider overloading though different in return type.
Q 4 - A protected member of the class in accessible in
Answer : B
Explaination
Only members of the derived class and the same class can access a protected member.
Q 5 - Runtime polymorphism is done using.
Answer : C
Explaination
Virtual functions gives the ability to override the functionality of base class into the derived class. Hence achieving dynamic/runtime polymorphism.
Q 6 - Choose the Object oriented programming language from below.
Answer : D
Explaination
Q 7 - Class function which is called automatically as soon as the object is created is called as __
Answer : A
Explaination
If not provided the same, default constructor from the compiler is called automatically otherwise the programmer’s provided constructor gets called.
Answer : B
Explaination
As it is also a character is occupies 1 byte of memory.
Q 9 - How can we make an class act as an interface in C++?
A - By only providing all the functions as virtual functions in the class.
B - Defining the class following with the keyword virtual
Answer : A
Explaination
There are no keywords in C++ such as abstract and interface.
Q 10 - The pointer which stores always the current active object address is __
Answer : B
Explaination
this is the keyword and acts as a pointer which always holds current active objects.
Answer : B
Explaination
False, as the static members do exist before the object of the respective class are created. 'this' is not applicable in the said context.
Q 12 - Designer of C++ programming language.
Answer : D
Explaination
Q 13 - How many number of arguments can a destructor of a class receives?
Answer : A
Explaination
The destructor receives no arguments and is only form to be provided. Hence destructor cannot be overloaded.
Q 14 - What is the output of the following program?
#include<iostream> using namespace std; class Base { public: virtual void f() { cout<<"Base\n"; } }; class Derived:public Base { public: void f() { cout<<"Derived\n"; } }; main() { Base *p = new Derived(); p->f(); }
Answer : B
Explaination
The overridden method f() of the created object for derived class gets called.
#include<iostream> using namespace std; class Base { public: virtual void f() { cout<<"Base\n"; } }; class Derived:public Base { public: void f() { cout<<"Derived\n"; } }; main() { Base *p = new Derived(); p->f(); }
Q 15 - 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 16 - 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() { Derived obj; obj.Base::f(); }
Answer : A
Explaination
The method f() inherited from Base is referred using :: operator.
#include<iostream> using namespace std; class Base { public: void f() { cout<<"Base\n"; } }; class Derived:public Base { public: void f() { cout<<"Derived\n"; } }; main() { Derived obj; obj.Base::f(); }
Q 17 - 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() { Derived obj; obj.Base::f(); }
Answer : A
Explaination
Base object cannot refer to Derived members.
#include<iostream> using namespace std; class Base { public: void f() { cout<<"Base\n"; } }; class Derived:public Base { public: void f() { cout<<"Derived\n"; }; }; main() { Derived obj; obj.Base::f(); }
Q 18 - What is the output of the following program?
#include<iostream> using namespace std; main() { int *p = new int; delete p; delete p; cout<<"Done"; }
Answer : C
Explaination
It is invalid to release memory more than once.
#include<iostream> using namespace std; main() { int *p = new int; delete p; delete p; cout<<"Done"; }
Q 19 - What is the output of the following program?
#include<iostream> using namespace std; main() { int const a = 5; a++; cout<<a; }
Answer : D
Explaination
Compile error - constant variable cannot be modified.
Q 20 - Which operator is used to resolve the scope of the global variable?
Answer : D
Explaination
Scope resolution operator is used to resolve for the global scope of a variable if the local and global variables conflict by name.
Q 21 - Which feature of the OOPS gives the concept of reusability?
Answer : C
Explaination
The process of designing a new class (derived) from the existing (base) class to acquire the attributes of the existing is called as inheritance. Inheritance gives the concept of reusability for code/software components.
Q 22 - Objects created using new operator are stored in __ memory.
Answer : B
Explaination
new operator allocates memory dynamically know as Heap/free memory.
Q 23 - What is the full form of RTTI.
A - Runtime type identification
B - Runtime template identification
Answer : A
Explaination
Q 24 - The programs machine instructions are store in __ memory segment.
Answer : D
Explaination
Code segments holds the program instructions and fetched by instruction pointer for execution.
Q 25 - The copy constructor is executed on
A - Assigned one object to another object at its creation
B - When objects are sent to function using call by value mechanism
Answer : D
Explaination
Options (a), (b) & (c) are applicable.
Answer Sheet
Question Number | Answer Key |
---|---|
1 | C |
2 | B |
3 | B |
4 | B |
5 | C |
6 | D |
7 | A |
8 | B |
9 | A |
10 | B |
11 | B |
12 | D |
13 | A |
14 | B |
15 | A |
16 | A |
17 | C |
18 | C |
19 | D |
20 | D |
21 | C |
22 | B |
23 | A |
24 | D |
25 | D |