C++ Online Test

This C++ Online Test simulates a real online certification exam. You will be presented with Multiple-Choice Questions (MCQs) based on C++ programming language concepts, where you will be given four options. You will select the best suitable answer for each question and then proceed to the next question without wasting time. You will get your online test score after finishing the complete test.

1. What does the C++ STL stand for?

a) Standard Template Library
b) Standard Type Library
c) Static Template Library
d) Standard Template Language

2. Which of the following is a correct comment in C++?

a) # This is a comment
b) /* This is a comment */
c) <!– This is a comment –>
d) ** This is a comment **

3. What is the output of sizeof(bool) on most implementations?

a) 1
b) 2
c) 4
d) 8

4. What is the correct way to create an object in C++?

a) className objectName;
b) className.objectName();
c) className = new objectName;
d) new className objectName;

5. Which keyword is used to define a class in C++?

a) class
b) Class
c) object
d) struct

6. What is the scope resolution operator in C++?

a) ::
b) ::
c) ->
d) :

7. Which header file must be included to use the cout and cin objects?

a) #include <string>
b) #include <iostream>
c) #include <stdio.h>
d) #include <ostream>

8. What is the default access specifier for members of a class in C++?

a) public
b) private
c) protected
d) None of the above

9. Which of the following is a use of virtual functions in C++?

a) To allow class specific functionality
b) To create constants
c) To perform I/O operations
d) To achieve runtime polymorphism

10. Which is the correct way to refer to a static member variable count of a class Test?

a) Test::count
b) Test.count
c) Test->count
d) Test-count

11. How can multiple inheritance be implemented in C++?

a) Using multiple classes separated by a comma
b) By inheriting classes in multiple lines
c) Using a single class multiple times
d) C++ does not support multiple inheritance

12. What is the output type of a dynamic_cast operation that fails when casting a pointer?

b) Zero
c) It throws an exception
d) nullptr

13. What does delete keyword do in C++?

a) Deletes variables declared statically
b) Frees memory allocated dynamically
c) Removes variables from a program
d) None of the above

14. Which collection is used for implementing a FIFO (First In, First Out) structure?

a) std::map
b) std::vector
c) std::stack
d) std::queue

15. Which of the following correctly declares an abstract class?

a) class with only private members
b) class with at least one pure virtual function
c) class without any member functions
d) class declared with the abstract keyword

16. In C++, what is the purpose of the mutable keyword?

a) Allows a member of an object to be modified even if the object is constant
b) Makes an instance of a class constant
c) Declares a variable that must not be modified
d) None of the above

17. Which keyword is used to prevent overriding of function in C++?

a) nooverride
b) final
c) seal
d) fix

18. What is the correct syntax to create a reference variable of an integer?

a) int &ref = var;
b) int ref = &var;
c) int *ref = var;
d) int ref = var;

19. What does the explicit keyword prevent?

a) Implicit type conversion
b) Explicit type conversion
c) Both implicit and explicit type conversion
d) None of the above

20. Which function is called when an object is deleted or removed?

a) finalizer()
b) destructor()
c) remover()
d) deleter()

21. What is the result of including the same header file multiple times in C++?

a) Compilation error
b) Redefinition error
c) No effect, due to include guards
d) Memory overflow

22. What is the correct way to declare a pointer to a constant integer?

a) int *const ptr;
b) const int ptr;
c) int const *ptr;
d) const int *ptr;

23. What is a namespace used for in C++?

a) To control the scope of class members
b) To package code into a logical structure
c) To prevent name conflicts
d) All of the above

24. What is an lvalue?

a) A value that cannot stand on the left side of an assignment
b) A location value, which represents an object that occupies some identifiable location in memory
c) A literal value
d) A temporary value

25. Which operator is used to resolve scope in C++?

a) ::
b) . and ->
c) ::
d) ->

26. What type of inheritance occurs when a class inherits from more than one base class?

a) Single inheritance
b) Multiple inheritance
c) Multilevel inheritance
d) Hierarchical inheritance

27. How do you specify that a class member remains in memory for the duration of the program?

a) static
b) const
c) volatile
d) register

28. What is the purpose of the this pointer?

a) To store the address of the calling object
b) To pass objects by reference
c) To access static members
d) To return the current function

29. What is the correct way to handle exceptions in C++?

a) using if-else conditions
b) using the error() function
c) using try, catch, and throw blocks
d) using the exception class

30. Which header file must be included to use the std::string class?

a) #include <string.h>
b) #include <strings>
c) #include <string>
d) #include <text>

31. What does the sizeof() operator return?

a) The size of a data type or variable in bytes
b) The size of a data type or variable in bits
c) The length of an array
d) The memory address of the variable

32. Which operator is used for dynamic memory allocation?

a) malloc
b) new
c) alloc
d) memory

33. What is the output of int i = 10; cout << ++i + i++;?

a) 20
b) 21
c) 22
d) Undefined

34. What keyword is used to define a macro in C++?

a) macro
b) #macro
c) define
d) #define

35. Which data type would you use to store a character in C++?

a) char
b) int
c) string
d) wchar_t

36. What is function overloading?

a) Giving multiple meanings to the function name
b) Defining the function multiple times
c) Changing the return type of the function
d) None of the above

37. What is the correct syntax for namespace declaration?

a) namespace name {}
b) package name {}
c) library name {}
d) module name {}

38. Which of the following is not a type of constructor in C++?

a) Copy constructor
b) Friend constructor
c) Default constructor
d) Parameterized constructor

39. What is meant by method overriding in C++?

a) Changing the way a method works
b) Extending the functionality of a method
c) A subclass provides a specific implementation of a method that is already provided by one of its superclasses
d) Two methods having the same name within the same class

40. Which concept allows you to reuse the properties and behavior of an existing class when you create a new class?

a) Polymorphism
b) Inheritance
c) Encapsulation
d) Abstraction

41. What does the auto keyword do?

a) It automatically initializes variables.
b) It infers the type of the variable by the value assigned to it.
c) It makes variables constant.
d) It is used for automatic memory management.

42. What is the difference between class and struct in C++?

a) Class members are private by default, struct members are public by default.
b) Struct does not support inheritance.
c) Classes are used for data storage, structs for more complex objects.
d) There is no difference.

43. How do you declare a function inline?

a) inline function-name();
b) function-name() inline;
c) inline type function-name();
d) type inline function-name();

44. What is the lifetime of a static variable within a function?

a) Same as the function call
b) While the program is running
c) Only during the block execution in which it is declared
d) It does not have a lifetime

45. What is meant by constant expression in C++?

a) An expression where the value changes during program execution
b) An expression that is not modified and evaluated at compile time
c) A literal value
d) An expression that must be evaluated during runtime

46. Which of the following is a correct operator to access members of a pointer to a class?

a) ::
b) .
c) ->
d) ::

47. What is the use of the volatile keyword?

a) It tells the compiler that a variable's value may change at any time without any action being taken by the code the compiler finds nearby.
b) It makes the variable permanently stored in memory.
c) It ensures that the variable is not optimized.
d) Both a and c

48. What does the typeid operator do?

a) Returns the type of variable.
b) Checks the type compatibility.
c) Returns the type_info object representing the type.
d) Converts a type to another type.

49. What is the output of the following statement if x = 10 and y = 10?

cout << (x == y);
a) 1
b) True
c) 10

50. Which is the correct operator for pointer access?

a) ->
b) :
c) *
d) &

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top