BPSC Tre 4.0 C++ MCQ Practice set Computer teacher 2025

 Here are 50 important C++ multiple-choice questions (MCQs) along with their answers:

  1. Which of the following is the correct syntax to include a header file in C++?

    • a) #include "headerfile"
    • b) include
    • c) #include
    • d) #include [headerfile]

    Answer: c) #include

  2. Which of the following operators cannot be overloaded in C++?

    • a) +
    • b) /
    • c) ::
    • d) -

    Answer: c) ::

  3. Which of the following is the default access modifier for class members in C++?

    • a) public
    • b) private
    • c) protected
    • d) none of the above

    Answer: b) private

  4. Which of the following is a correct example of a pointer in C++?

    • a) int *ptr;
    • b) ptr = &x;
    • c) *ptr = 5;
    • d) All of the above

    Answer: d) All of the above

  5. What will be the output of the following code?

    int x = 10;
    cout << ++x;
    
    • a) 10
    • b) 11
    • c) Error
    • d) None of the above

    Answer: b) 11

  6. Which of the following is a function that does not return any value?

    • a) void function()
    • b) int function()
    • c) float function()
    • d) None of the above

    Answer: a) void function()

  7. Which of the following is true about constructors in C++?

    • a) Constructors are used to initialize objects.
    • b) Constructors must have the same name as the class.
    • c) Constructors do not have a return type.
    • d) All of the above

    Answer: d) All of the above

  8. What is the output of the following code?

    int x = 5;
    cout << (x++);
    
    • a) 5
    • b) 6
    • c) Error
    • d) None of the above

    Answer: a) 5

  9. Which of the following is used to allocate memory dynamically in C++?

    • a) malloc()
    • b) new
    • c) calloc()
    • d) free()

    Answer: b) new

  10. Which of the following is the correct way to declare a constant variable in C++?

    • a) const int x = 10;
    • b) int const x = 10;
    • c) Both a and b
    • d) None of the above

    Answer: c) Both a and b

  11. Which of the following statements is correct about the destructors in C++?

    • a) Destructor is used to initialize objects.
    • b) Destructor has the same name as the class.
    • c) Destructor must return a value.
    • d) Destructor cannot be overloaded.

    Answer: b) Destructor has the same name as the class.

  12. Which of the following is used for type conversion in C++?

    • a) cast()
    • b) (type)expression
    • c) type_cast()
    • d) None of the above

    Answer: b) (type)expression

  13. What is the output of the following code?

    int a = 10;
    int b = 20;
    cout << a + b;
    
    • a) 10
    • b) 20
    • c) 30
    • d) Error

    Answer: c) 30

  14. Which of the following is the correct syntax for a while loop in C++?

    • a) while (condition) { // statements }
    • b) do { // statements } while (condition);
    • c) for (int i = 0; i < 10; i++) { // statements }
    • d) All of the above

    Answer: a) while (condition) { // statements }

  15. Which of the following is a valid C++ data type?

    • a) integer
    • b) int
    • c) float32
    • d) double64

    Answer: b) int

  16. What will be the output of the following code?

    int x = 5;
    cout << --x;
    
    • a) 4
    • b) 5
    • c) 6
    • d) Error

    Answer: a) 4

  17. Which of the following statements is used to terminate a loop in C++?

    • a) exit()
    • b) break
    • c) continue
    • d) return

    Answer: b) break

  18. Which of the following types of inheritance is not allowed in C++?

    • a) Single inheritance
    • b) Multiple inheritance
    • c) Multilevel inheritance
    • d) Cyclic inheritance

    Answer: d) Cyclic inheritance

  19. Which of the following C++ concepts allows the same function name to be used for different functions with different signatures?

    • a) Inheritance
    • b) Polymorphism
    • c) Encapsulation
    • d) Overloading

    Answer: d) Overloading

  20. Which of the following will be used to access the class member from outside the class in C++?

    • a) dot operator
    • b) scope resolution operator
    • c) arrow operator
    • d) pointer operator

    Answer: a) dot operator

  21. Which of the following operators is used to allocate memory dynamically in C++?

    • a) malloc
    • b) new
    • c) delete
    • d) free

    Answer: b) new

  22. Which of the following is the correct syntax for a switch statement in C++?

    • a) switch(expression) { case value: // code }
    • b) switch(expression) { case: value; }
    • c) switch (value) { case expression: // code }
    • d) switch(expression) { default: }

    Answer: a) switch(expression) { case value: // code }

  23. What does the term "inheritance" in C++ mean?

    • a) The ability to take on the attributes and behavior of another class.
    • b) The ability to override a method of a base class.
    • c) The ability to call a method from another class.
    • d) None of the above.

    Answer: a) The ability to take on the attributes and behavior of another class.

  24. Which of the following access modifiers restricts access to members of a class to the members of the same class only?

    • a) public
    • b) private
    • c) protected
    • d) friend

    Answer: b) private

  25. Which of the following is used to stop the execution of a loop immediately in C++?

    • a) break
    • b) exit
    • c) continue
    • d) return

    Answer: a) break

  26. Which of the following is used to define a constant in C++?

    • a) const
    • b) final
    • c) constant
    • d) define

    Answer: a) const

  27. Which of the following is the correct way to declare a reference in C++?

    • a) int &x;
    • b) int x&;
    • c) ref int x;
    • d) None of the above

    Answer: a) int &x;

  28. Which function in C++ is called when an object goes out of scope?

    • a) Destructor
    • b) Constructor
    • c) Finalizer
    • d) Destructor and Constructor

    Answer: a) Destructor

  29. Which of the following C++ keywords is used to define a function that will never return a value?

    • a) void
    • b) null
    • c) empty
    • d) None of the above

    Answer: a) void

  30. What is the function of the 'new' keyword in C++?

    • a) It creates a new instance of a class.
    • b) It allocates memory for an object dynamically.
    • c) It initializes a class.
    • d) None of the above.

    Answer: b) It allocates memory for an object dynamically.

  31. What is the correct way to declare a 2D array in C++?

    • a) int arr[3][4];
    • b) int arr(3, 4);
    • c) int arr[3, 4];
    • d) int arr{3}{4};

    Answer: a) int arr[3][4];

  32. Which of the following operators is used to access members of a class through a pointer to an object in C++?

    • a) dot operator (.)
    • b) arrow operator (->)
    • c) scope resolution operator (::)
    • d) None of the above

    Answer: b) arrow operator (->)

  33. Which of the following is a valid pointer declaration in C++?

    • a) int *p;
    • b) *int p;
    • c) p* int;
    • d) None of the above

    *Answer: a) int p;

  34. What is a pure virtual function in C++?

    • a) A function that has no implementation.
    • b) A function that is overridden in derived classes.
    • c) A function that can only be accessed by the derived class.
    • d) None of the above

    Answer: a) A function that has no implementation.

  35. Which of the following C++ features supports function overloading?

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

    Answer: a) Polymorphism

  36. What is the result of the expression 10 / 3 in C++?

    • a) 3.33
    • b) 3
    • c) 4
    • d) Error

    Answer: b) 3

  37. What will the following code output?

    int x = 2;
    x *= 3;
    cout << x;
    
    • a) 6
    • b) 2
    • c) 3
    • d) Error

    Answer: a) 6

  38. Which of the following is the correct declaration for an inline function in C++?

    • a) inline void function();
    • b) function inline void();
    • c) void function inline();
    • d) None of the above

    Answer: a) inline void function();

  39. Which of the following is a characteristic of C++?

    • a) Object-Oriented Programming
    • b) Procedural Programming
    • c) Both a and b
    • d) None of the above

    Answer: c) Both a and b

  40. Which of the following is used to allocate memory for a single object dynamically in C++?

    • a) new
    • b) malloc
    • c) calloc
    • d) None of the above

    Answer: a) new

  41. What is the size of a pointer variable in C++?

    • a) 1 byte
    • b) 2 bytes
    • c) 4 bytes
    • d) Depends on the system

    Answer: d) Depends on the system

  42. Which of the following is the correct method for declaring a function pointer in C++?

    • a) int (*ptr)();
    • b) void ptr*();
    • c) int ptr(*);
    • d) None of the above

    *Answer: a) int (ptr)();

  43. Which of the following is an example of a dynamic data structure?

    • a) Array
    • b) Linked List
    • c) Stack
    • d) None of the above

    Answer: b) Linked List

  44. What does the 'this' pointer refer to in C++?

    • a) It refers to the address of the current object.
    • b) It refers to the base class.
    • c) It is used for dynamic memory allocation.
    • d) None of the above

    Answer: a) It refers to the address of the current object.

  45. What will be the output of the following code?

    int a = 5;
    int b = 2;
    cout << a / b;
    
    • a) 2
    • b) 2.5
    • c) 5
    • d) Error

    Answer: a) 2

  46. Which of the following is a method of a class in C++?

    • a) Function
    • b) Constructor
    • c) Destructor
    • d) All of the above

    Answer: d) All of the above

  47. Which of the following can be used to handle exceptions in C++?

    • a) try-catch blocks
    • b) throw
    • c) catch
    • d) All of the above

    Answer: d) All of the above

  48. Which of the following is an example of a virtual function in C++?

    • a) void display() virtual;
    • b) virtual void display();
    • c) display() virtual void;
    • d) None of the above

    Answer: b) virtual void display();

  49. Which of the following C++ features allows data hiding?

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

    Answer: a) Encapsulation

  50. What is the output of the following code?

    int a = 10;
    int b = 5;
    cout << a % b;
    
    • a) 2
    • b) 5
    • c) 10
    • d) 0

    Answer: d) 0

Comments

Latest Books