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.
Q 1 - The default access specifer for the class members is
A - public
B - private
C - protected
D - None of the above.
If a member/s appear in the class with following no access specifier, the default is private.
Q 2 - A trigraph character begins with
A - #
B - ##
C - ?
D - ??
Few characters have alternative representation and start with ??. Eg. Fro [ equivalent is ??(
Q 3 - C++ does not supports the following
A - Multilevel inheritance
B - Hierarchical inheritance
C - Hybrid inheritance
D - None of the above.
C++ supports all the forms of inheritance.
Q 4 - One of the following is true for an inline function.
A - It executes faster as it is treated as a macro internally
B - It executes faster because it priority is more than normal function
C - It doesn’t executes faster compared to a normal function
D - None of the above holds true for an inline function
 As inline function gets expanded at the line of call like a macro it executes faster.
Q 5 - Choose the pure virtual function definition from the following.
A - virtual void f()=0 {  }
B - void virtual f()=0 {  }
C - virtual void f() {} = 0;
D - None of the above.
 A pure virtual function cannot have a definition.
Q 6 - Abstract class is __
A - A class must contain all pure virtual functions
B - A class must contain at least one pure virtual function
C - A class may not contain pure virtual function.
D - A class must contain pure virtual function defined outside the class.
It is sufficient to have one pure virtual function in the class to make it as an abstract class.
Q 7 - What is the output of the following program?
#include<iostream>

using namespace std;
class abc { 
   void f();
   void g();
   int x;
};

main() {
   cout<<sizeof(abc)<<endl;
}
A - 12
B - 4
C - 8
D - Compile error
Only the class member variables constitutes as the size of the class or its object.
#include<iostream>

using namespace std;
class abc { 
   void f();
   void g();
   int x;
};
main() {
   cout<<sizeof(abc)<<endl;
}
Q 8 - 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;
}
A - 3 1
B - 3 3
C - 1 1
D - 1 3
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 9 - A constructor can be virtual.
A -  True
B - False
The purpose of the constructor cannot be overridden in the derived class hence constructor cannot be a virtual.
Q 10 - Choose the operator which cannot be overloaded.
A - /
B - ()
C - ::
D - %
Scope resolution (::) is not permitted to be overloaded.
Q 11 - Which operator is required to be overloaded as member function only?
A - _
B - _ _
C - ++ (postfix version)
D - =
Overloaded assignment operator does the job similar to copy constructor and is required to be overloaded as member function of the class.
Q 12 - Which of the following is not the keyword in C++?
A - volatile
B - friend
C - extends
D - this
All the rest are valid keywords of C++.
Q 13 - What is the output of the following program?
#include<iostream>

using namespace std;
class abc { 

   public: 
      int i; 

      abc(int i) { 
         i = i;
      }
};

main() { 
   abc m(5); 
   
   cout<<m.i;
}
A - 5
B - Garbage
C - Error at the statement i=i;
D - Compile error: ‘i’ declared twice.
i=i, is assigning member variable to itself.
#include<iostream>

using namespace std;
class abc { 

   public: 
      int i; 

      abc(int i) { 
         i = i;
      }
};

main() { 
   abc m(5); 
   
   cout<<m.i;
}
Q 14 - By default the members of the structure are
A - private
B - protected
C - public
D - Access specifiers not applicable for structures.
If no access specifiers are specified for structure variables/functions, then the default is considered as public.
Q 15 - From the below class choose the proper definition of the member function f().
template <class T>

class abc {
   void f();
};
A - template <class T> 
    void abc<T>::f() { }
B - template<class T> 
    void abc::f() { }
C - template<T> 
    void abc<class T>::f() { }
D - template<T> 
    void abc<T>::f() { }
 
Q 16 - Choose the respective delete operator usage for the expression ‘ptr=new int[100]’.
A - delete ptr;
B - delete ptr[];
C - delete[] ptr;
D - []delete ptr;
 
Q 17 - ‘cin’ is an __
A - Class
B - Object
C - Package
D - Namespace
It’s an object of istream class.
Q 18 -  The operator used to access member function of a structure using its object.
A - .
B - ->
C - *
D - None of the above.
Just the way we use dot (.) operator to access members of the class, in similar it is used to access the members of the structure too.
Q 19 - A user defined header file is included by following statement in general.
A - #include “file.h”
B - #include <file.h>
C - #include <file>
D - #include file.h
With the syntax as in (a) the compiler first looks for the file in the present working directory and then in the default include path if not found.
Q 20 - Which data type can be used to hold a wide character in C++?
A - unsigned char;
B - int
C - wchar_t
D - none of the above.
wchar_t is the data type using which we can hold Unicode characters.
Q 21 - Which is the storage  specifier used to modify the member variable even though the class object is a constant object?
A - auto
B - register
C - static
D - mutable
mutable 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 22 - The following operator can be used to calculate the value of one number raised to another.
A - ^
B - **
C - ^^
D -None of the above
There is no such operator in C/C++.
Q 23 - Pick up the valid declaration for overloading ++ in postfix form where T is the class name.
A - T operator++();
B - T operator++(int);
C - T& operator++();
D - T& operator++(int);
The parameter int is just to signify that it is the postfix form overloaded. Shouldn’t return reference as per its original behavior.
Q 24 - We can have varying number of arguments for the overloaded form of () operator.
A - True
B - False
 
Q 25 - Operators sizeof and ?:
A - Both can be overloaded
B - Both cannot be overloaded
C - Only sizeof can be overloaded
D - Only ?: can be overloaded
Both the mentioned operators cannot be overloaded.

    154 Lectures 
     11.5 hours 

 Arnab Chakraborty

    14 Lectures 
     57 mins

 Kaushik Roy Chowdhury

    30 Lectures 
     12.5 hours 

 Frahaan Hussain

    54 Lectures 
     3.5 hours 

 Frahaan Hussain

    77 Lectures 
     5.5 hours 

 Frahaan Hussain

    12 Lectures 
     3.5 hours 

 Frahaan Hussain
 Print
 Add Notes
 Bookmark this page