100 C++ MCQ (Multiple Choice Questions) with Answers

1) Who developed the C++ programming language?
  1. Dennis Ritchie
  2. Bjarne Stroustrup
  3. James Gosling
  4. Guido van Rossum
Show Answer
Answer: b


2) Which standard output stream is used in C++ to display text?

  1. printf()
  2. cout
  3. cin
  4. System.out.println
Show Answer
Answer: b


3) Which header file is needed to use std::cout and std::cin?

  1. <stdio.h>
  2. <stdlib.h>
  3. <iostream>
  4. <string>
Show Answer
Answer: c


4) What is the standard extension of a C++ source code file?

  1. .c
  2. .cpp
  3. .class
  4. .cp
Show Answer
Answer: b


5) Which operator is used for input stream insertion in C++?

  1. <<
  2. >>
  3. ->
  4. ::
Show Answer
Answer: b


6) Which operator is used for scope resolution in C++?

  1. .
  2. ->
  3. ::
  4. :
Show Answer
Answer: c


7) Which keyword is used to define a class in C++?

  1. struct
  2. class
  3. object
  4. interface
Show Answer
Answer: b


8) What is the default access modifier for members of a class in C++?

  1. public
  2. protected
  3. private
  4. package-private
Show Answer
Answer: c


9) What is the default access specifier for members of a struct in C++?

  1. private
  2. public
  3. protected
  4. internal
Show Answer
Answer: b


10) Which keyword is used to allocate memory dynamically in C++?

  1. malloc
  2. alloc
  3. new
  4. create
Show Answer
Answer: c


11) Which operator is used to deallocate dynamic memory allocated with new?

  1. free
  2. delete
  3. remove
  4. clear
Show Answer
Answer: b


12) Which keyword is used to pass a parameter by reference without creating a copy?

  1. *
  2. &
  3. ref
  4. pointer
Show Answer
Answer: b


13) What function is called automatically when an object is created?

  1. Destructor
  2. Constructor
  3. Virtual Function
  4. Inline Function
Show Answer
Answer: b


14) What symbol precedes the name of a destructor function in C++?

  1. #
  2. ~
  3. *
  4. !
Show Answer
Answer: b


15) Can a constructor be overloaded in C++?

  1. Yes
  2. No
  3. Only in derived classes
  4. Only if declared private
Show Answer
Answer: a


16) Can a destructor be overloaded in C++?

  1. Yes
  2. No
  3. Only if it takes no arguments
  4. Depends on the compiler
Show Answer
Answer: b


17) Which feature allows defining multiple functions with the same name but different parameters?

  1. Function Overriding
  2. Function Overloading
  3. Virtual Functions
  4. Abstraction
Show Answer
Answer: b


18) What is function overriding?

  1. Defining multiple functions in the same class with different parameters
  2. Redefining a base class method in a derived class with the same signature
  3. Calling a function recursively
  4. Hiding global variables
Show Answer
Answer: b


19) Which keyword is used to make a method support dynamic binding / runtime polymorphism?

  1. inline
  2. virtual
  3. override
  4. static
Show Answer
Answer: b


20) What is a class containing at least one pure virtual function called?

  1. Concrete class
  2. Abstract class
  3. Interface class
  4. Sealed class
Show Answer
Answer: b


21) What is the syntax for declaring a pure virtual function in C++?

  1. virtual void display() = 0;
  2. virtual void display();
  3. pure virtual void display();
  4. void display() = pure;
Show Answer
Answer: a


22) Which operator cannot be overloaded in C++?

  1. +
  2. ::
  3. []
  4. ()
Show Answer
Answer: b


23) Which of the following operators CANNOT be overloaded?

  1. sizeof
  2. ?:
  3. .
  4. All of the above
Show Answer
Answer: d


24) Which keyword is used to grant a non-member function access to private members of a class?

  1. public
  2. friend
  3. protected
  4. export
Show Answer
Answer: b


25) What pointer refers to the current invoking instance inside a member function?

  1. super
  2. this
  3. self
  4. base
Show Answer
Answer: b


26) Which type of inheritance allows a derived class to inherit from multiple base classes?

  1. Single Inheritance
  2. Multilevel Inheritance
  3. Multiple Inheritance
  4. Hierarchical Inheritance
Show Answer
Answer: c


27) What problem arises when a class inherits from two classes that both inherit from the same base class?

  1. Diamond Problem
  2. Circular Dependency
  3. Stack Overflow
  4. Dangling Pointer
Show Answer
Answer: a


28) Which keyword resolves the Diamond Problem when declaring base class inheritance?

  1. friend
  2. virtual
  3. override
  4. static
Show Answer
Answer: b


29) What is the output of sizeof(bool) in standard C++?

  1. 1 byte
  2. 2 bytes
  3. 4 bytes
  4. Compiler-dependent
Show Answer
Answer: a


30) Which keyword is used to define template functions or classes in C++?

  1. template
  2. generic
  3. typename
  4. Both a and c
Show Answer
Answer: d


31) Which exception handling keyword is used to inspect a code block for errors?

  1. catch
  2. try
  3. throw
  4. finally
Show Answer
Answer: b


32) Which keyword is used to signal the occurrence of an exception?

  1. raise
  2. throw
  3. catch
  4. error
Show Answer
Answer: b


33) Which block handles an exception thrown from a try block?

  1. catch
  2. except
  3. finally
  4. rescue
Show Answer
Answer: a


34) What does STL stand for in C++?

  1. System Type Library
  2. Standard Template Library
  3. Single Thread Logic
  4. Standard Text Language
Show Answer
Answer: b


35) Which container in STL represents a dynamic contiguous array?

  1. std::list
  2. std::vector
  3. std::map
  4. std::set
Show Answer
Answer: b


36) Which STL container is implemented as a doubly linked list?

  1. std::vector
  2. std::deque
  3. std::list
  4. std::set
Show Answer
Answer: c


37) Which STL container stores unique elements in sorted order?

  1. std::set
  2. std::vector
  3. std::list
  4. std::unordered_set
Show Answer
Answer: a


38) Which header file is required to use std::vector?

  1. <array>
  2. <vector>
  3. <list>
  4. <container>
Show Answer
Answer: b


39) What method returns the number of elements in a std::vector?

  1. length()
  2. size()
  3. count()
  4. capacity()
Show Answer
Answer: b


40) What method adds an element to the end of a std::vector?

  1. append()
  2. push_back()
  3. insert()
  4. add()
Show Answer
Answer: b


41) What is the output of 7 / 2 in C++ integer arithmetic?

  1. 3.5
  2. 3
  3. 4
  4. 3.0
Show Answer
Answer: b


42) What is the result of 7 % 2 in C++?

  1. 1
  2. 3.5
  3. 0
  4. 2
Show Answer
Answer: a


43) Which keyword is used to prevent modification of a variable’s value?

  1. static
  2. const
  3. constexpr
  4. Both b and c
Show Answer
Answer: d


44) What keyword was introduced in C++11 for automatic type deduction?

  1. var
  2. auto
  3. type
  4. decltype
Show Answer
Answer: b


45) Which value represents a null pointer constant introduced in C++11?

  1. NULL
  2. 0
  3. nullptr
  4. void*
Show Answer
Answer: c


46) What does RAII stand for in C++ programming?

  1. Resource Acquisition Is Initialization
  2. Runtime Access In Inheritance
  3. Random Allocation In Iteration
  4. Reference Access And Inspection
Show Answer
Answer: a


47) Which smart pointer provides exclusive ownership of an object?

  1. std::shared_ptr
  2. std::unique_ptr
  3. std::weak_ptr
  4. std::auto_ptr
Show Answer
Answer: b


48) Which smart pointer uses reference counting to manage shared ownership?

  1. std::unique_ptr
  2. std::shared_ptr
  3. std::weak_ptr
  4. std::raw_ptr
Show Answer
Answer: b


49) Which header file is required for smart pointers like std::unique_ptr?

  1. <pointer>
  2. <memory>
  3. <utility>
  4. <stdlib.h>
Show Answer
Answer: b


50) What keyword suggests to the compiler to inline a function to reduce call overhead?

  1. inline
  2. fast
  3. macro
  4. static
Show Answer
Answer: a


51) What type of casting is used for conversion between related class pointer types at runtime?

  1. static_cast
  2. dynamic_cast
  3. reinterpret_cast
  4. const_cast
Show Answer
Answer: b


52) Which cast operator removes the const qualification from a variable?

  1. static_cast
  2. const_cast
  3. reinterpret_cast
  4. dynamic_cast
Show Answer
Answer: b


53) Which cast is used for low-level bitwise reinterpretation of memory addresses?

  1. reinterpret_cast
  2. static_cast
  3. dynamic_cast
  4. const_cast
Show Answer
Answer: a


54) What is the scope of a variable declared with static inside a function?

  1. Local to the function, but retains value across function calls
  2. Global to all files
  3. Destroyed as soon as the function exits
  4. Restricted to class members
Show Answer
Answer: a


55) How do you declare a constant expression evaluated at compile-time in C++11?

  1. const
  2. constexpr
  3. static const
  4. inline const
Show Answer
Answer: b


56) What is an anonymous inline function introduced in C++11 called?

  1. Virtual function
  2. Lambda expression
  3. Macro
  4. Template function
Show Answer
Answer: b


57) In a lambda expression [=]() { … }, what does [=] mean?

  1. Capture all external variables by value
  2. Capture all external variables by reference
  3. Capture nothing
  4. Return equal value
Show Answer
Answer: a


58) In a lambda expression [&]() { … }, what does [&] mean?

  1. Capture all external variables by value
  2. Capture all external variables by reference
  3. Pass arguments by reference
  4. Return address
Show Answer
Answer: b


59) What is the type of string literals like “Hello” in C++?

  1. std::string
  2. const char[]
  3. char*
  4. vector<char>
Show Answer
Answer: b


60) Which standard library header provides std::string?

  1. <string.h>
  2. <cstring>
  3. <string>
  4. <text>
Show Answer
Answer: c


61) Which method converts a std::string object to a C-style null-terminated string?

  1. to_char()
  2. c_str()
  3. str()
  4. data_str()
Show Answer
Answer: b


62) What does cin.get() do?

  1. Reads an entire line of text
  2. Reads a single character including whitespace
  3. Clears input stream
  4. Reads integers only
Show Answer
Answer: b


63) Which function reads an entire line including spaces into a std::string?

  1. cin >> str
  2. getline(cin, str)
  3. gets(str)
  4. cin.read(str)
Show Answer
Answer: b


64) What happens if delete is used on a memory allocated with new[] (array allocation)?

  1. Everything is deallocated cleanly
  2. Undefined behavior (should use delete[])
  3. Compile-time error
  4. Memory leaks are prevented automatically
Show Answer
Answer: b


65) What is the result of dereferencing a nullptr?

  1. Returns 0
  2. Undefined behavior / Segmentation Fault
  3. Returns NULL
  4. Throws a runtime_error
Show Answer
Answer: b


66) What is a pointer pointing to memory that has been deallocated called?

  1. Null pointer
  2. Dangling pointer
  3. Wild pointer
  4. Void pointer
Show Answer
Answer: b


67) What is an uninitialized pointer called?

  1. Wild pointer
  2. Null pointer
  3. Dangling pointer
  4. Smart pointer
Show Answer
Answer: a


68) What class stream is used for reading from files in C++?

  1. ofstream
  2. ifstream
  3. fstream
  4. stringstream
Show Answer
Answer: b


69) What class stream is used for writing to files in C++?

  1. ifstream
  2. ofstream
  3. iostream
  4. fileout
Show Answer
Answer: b


70) Which header file is required for file I/O operations in C++?

  1. <iostream>
  2. <fstream>
  3. <stdio.h>
  4. <file>
Show Answer
Answer: b


71) What mode flag in fstream appends output to the end of a file?

  1. std::ios::in
  2. std::ios::out
  3. std::ios::app
  4. std::ios::trunc
Show Answer
Answer: c


72) Which keyword specifies that a class member cannot be modified inside a const member function?

  1. mutable
  2. volatile
  3. static
  4. Member variables can be modified by default
Show Answer
Answer: a


73) What key property allows mutable data members to be modified?

  1. Modified inside const member functions
  2. Modified across multiple threads safely
  3. Cannot be initialized
  4. Stored in stack memory
Show Answer
Answer: a


74) What is the scope of protected members of a base class?

  1. Accessible only inside base class
  2. Accessible inside base class and derived classes
  3. Accessible everywhere
  4. Accessible within the same package
Show Answer
Answer: b


75) When a class inherits a base class publicly (class Derived : public Base), how do protected base members behave?

  1. Become private in derived
  2. Remain protected in derived
  3. Become public in derived
  4. Inaccessible
Show Answer
Answer: b


76) What happens to public members when inheriting privately (class Derived : private Base)?

  1. Become private in derived class
  2. Remain public
  3. Become protected
  4. Inaccessible
Show Answer
Answer: a


77) What operator is used to access members using an object reference or instance?

  1. .
  2. ->
  3. ::
  4. *
Show Answer
Answer: a


78) What operator is used to access members using an object pointer?

  1. .
  2. ->
  3. ::
  4. &
Show Answer
Answer: b


79) What feature allows a constructor to be called with a single argument without implicit type conversion?

  1. explicit keyword
  2. implicit keyword
  3. override keyword
  4. final keyword
Show Answer
Answer: a


80) What C++11 keyword prevents a class from being inherited or a virtual function from being overridden?

  1. stop
  2. final
  3. sealed
  4. const
Show Answer
Answer: b


81) What C++11 keyword explicitly specifies that a method overrides a base class virtual function?

  1. virtual
  2. override
  3. overload
  4. extends
Show Answer
Answer: b


82) What is the size of a empty class in C++?

  1. 0 bytes
  2. 1 byte
  3. 4 bytes
  4. Compiler crash
Show Answer
Answer: b


83) Why does an empty class have a non-zero size in C++?

  1. To ensure unique memory addresses for different object instances
  2. To store virtual table pointer
  3. Due to alignment padding
  4. For destructor memory
Show Answer
Answer: a


84) What is VTABLE in C++?

  1. A table of function pointers created for classes with virtual functions
  2. A list of variable names
  3. Memory table for dynamic arrays
  4. Template lookup table
Show Answer
Answer: a


85) What hidden pointer inside an object points to the VTABLE?

  1. vptr
  2. this
  3. vtable
  4. smart_ptr
Show Answer
Answer: a


86) When is the VTABLE resolution performed?

  1. Compile-time
  2. Run-time
  3. Preprocessing-time
  4. Linking-time
Show Answer
Answer: b


87) What is copy constructor signature for class A?

  1. A(A obj)
  2. A(const A &obj)
  3. A(A *obj)
  4. void A(A obj)
Show Answer
Answer: b


88) What occurs if a copy constructor takes parameter by value (A(A obj)) instead of reference?

  1. Infinite recursion / Compiler Error
  2. Normal copying
  3. Shallow copy
  4. Dynamic allocation
Show Answer
Answer: a


89) What type of copy duplicates pointer addresses rather than pointing to new memory allocations?

  1. Deep Copy
  2. Shallow Copy
  3. Smart Copy
  4. Reference Copy
Show Answer
Answer: b


90) What type of copy allocates new memory and duplicates actual data values?

  1. Deep Copy
  2. Shallow Copy
  3. Bitwise Copy
  4. Alias Copy
Show Answer
Answer: a


91) What rule states that if a class requires a custom destructor, copy constructor, or copy assignment operator, it likely needs all three?

  1. Rule of Three
  2. Rule of Five
  3. Rule of Zero
  4. Rule of Inheritance
Show Answer
Answer: a


92) With C++11 move semantics, Rule of Three expanded into which rule?

  1. Rule of Four
  2. Rule of Five
  3. Rule of Six
  4. Rule of Ten
Show Answer
Answer: b


93) Which operator was introduced in C++11 to support move semantics by referencing rvalues?

  1. &
  2. &&
  3. *
  4. ->*
Show Answer
Answer: b


94) Which standard library function converts an lvalue to an rvalue to enable moving?

  1. std::move()
  2. std::forward()
  3. std::copy()
  4. std::cast()
Show Answer
Answer: a


95) Which header file provides std::move and std::forward?

  1. <utility>
  2. <algorithm>
  3. <memory>
  4. <iostream>
Show Answer
Answer: a


96) Which header file contains general algorithms like std::sort, std::find, and std::reverse?

  1. <algorithm>
  2. <utility>
  3. <numeric>
  4. <vector>
Show Answer
Answer: a


97) What is the average time complexity of std::sort() in STL?

  1. O(N)
  2. O(N log N)
  3. O(N^2)
  4. O(log N)
Show Answer
Answer: b


98) Which namespace contains all standard C++ library components?

  1. sys
  2. std
  3. cpp
  4. main
Show Answer
Answer: b


99) Which keyword allows using components of a namespace without qualifying them explicitly?

  1. using
  2. import
  3. include
  4. namespace
Show Answer
Answer: a


100) What is the output of sizeof(int*) on a 64-bit operating system architecture?

  1. 2 bytes
  2. 4 bytes
  3. 8 bytes
  4. 16 bytes
Show Answer
Answer: c

 

100 C Programming MCQ (Multiple Choice Questions) with Answers
100 SQL MCQ (Multiple Choice Questions) with Answers
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment