Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
🟢 Foundation  ·  Lesson 01

Cpp Quiz

C++ Complete MCQ Quiz – 120 Questions

Total Marks: 120   |   Total Questions: 120   |   Time: 90 minutes   |   Marking: +1 for correct, 0 for wrong/unanswered.
  • One question will appear on the screen at a time.
  • Use Next and Previous buttons to move between questions.
  • Use the right-side question palette to jump to any question.
  • Use Mark for Review for questions you want to revisit.
  • The quiz auto-submits when time is over.
Complete Quiz 120 Marks
90:00
Question 1 of 120

Question Palette

Purple = Answered
Yellow = Review
White = Not Answered

Answer key with explanations

Attempt the test and submit it first, then use this key to revise. Each answer has a short explanation so you understand why it is correct.

Show all 120 answers
  1. Which function is the starting point of every executable C++ program?

    Answer: B. main() – main() is the entry point of a C++ program.

  2. Which header is commonly used for cout and cin?

    Answer: B. <iostream> – iostream provides standard input and output streams.

  3. Which operator is used with cout?

    Answer: B. << – cout uses insertion operator <<.

  4. Which operator is used with cin?

    Answer: B. >> – cin uses extraction operator >>.

  5. What does return 0 generally indicate in main()?

    Answer: B. Program completed successfully – return 0 means successful completion.

  6. Which extension is normally used for C++ source files?

    Answer: A. .cpp – .cpp is the common extension for C++ source code.

  7. Which command can compile main.cpp using g++?

    Answer: A. g++ main.cpp -o main – g++ main.cpp -o main compiles and names executable main.

  8. Which keyword creates an unchangeable variable value?

    Answer: B. const – const makes a value read-only after initialization.

  9. Which data type stores true or false?

    Answer: C. bool – bool stores true or false values.

  10. Which data type is best for decimal marks like 92.5?

    Answer: B. double – double stores decimal values accurately enough for common calculations.

  11. Which is a valid C++ variable name?

    Answer: C. total_marks – total_marks is valid; spaces and starting with digit are invalid, class is keyword.

  12. Which symbol ends most C++ statements?

    Answer: B. ; – Semicolon ends most statements.

  13. Which comment is single-line in C++?

    Answer: A. // comment – // creates a single-line comment.

  14. What is namespace std used for?

    Answer: A. To access standard library names – std contains cout, cin, string, vector and many standard names.

  15. Which is the correct way to print Hello?

    Answer: C. cout << "Hello"; – cout << value prints output.

  16. What is integer division result of 5 / 2 in C++ when both operands are int?

    Answer: B. 2 – Integer division removes decimal part.

  17. Which operator gives remainder?

    Answer: B. % – % gives remainder of integer division.

  18. Which operator checks equality?

    Answer: B. == – == compares two values for equality.

  19. Which logical operator means AND?

    Answer: A. && – && is logical AND.

  20. Which logical operator means OR?

    Answer: B. || – || is logical OR.

  21. Which statement is best for range checking marks?

    Answer: A. if-else – if-else handles ranges like marks >= 90.

  22. Which keyword handles unmatched switch cases?

    Answer: B. default – default handles unmatched switch values.

  23. Why is break used in switch?

    Answer: B. To prevent fall-through – break stops execution from continuing into next case.

  24. How many times does for(int i=1;i<=3;i++) run?

    Answer: C. 3 – i takes values 1,2,3.

  25. Which loop executes at least once?

    Answer: C. do-while – do-while checks condition after body.

  26. What does continue do?

    Answer: B. Skips current iteration – continue skips remaining body for current iteration.

  27. What does break do inside a loop?

    Answer: B. Terminates loop – break exits the nearest loop.

  28. Array indexing in C++ starts from

    Answer: A. 0 – C++ arrays use zero-based indexing.

  29. If int a[5]; valid last index is

    Answer: B. 4 – For size 5, indexes are 0 to 4.

  30. Which header is used for C++ string class?

    Answer: A. <string> – <string> provides std::string.

  31. Which function reads a full line into a string?

    Answer: B. getline – getline(cin, str) reads spaces too.

  32. A function that returns no value uses return type

    Answer: B. void – void means no return value.

  33. Which is true about recursion?

    Answer: A. Function calls itself – Recursive function calls itself and needs base case.

  34. Base case in recursion is used to

    Answer: B. Stop recursion – Base case stops recursive calls.

  35. A reference is best described as

    Answer: A. Alias for another variable – Reference is another name for an existing variable.

  36. Which symbol is used to get address of a variable?

    Answer: B. & – & gives address of a variable.

  37. Which symbol dereferences a pointer?

    Answer: B. * – *p gives value at address stored in p.

  38. Which value should be used for a pointer that points nowhere?

    Answer: B. nullptr – nullptr is modern C++ null pointer.

  39. Which keyword allocates dynamic memory in C++?

    Answer: B. new – new allocates memory in C++.

  40. Which keyword releases memory allocated by new?

    Answer: B. delete – delete releases memory allocated by new.

  41. A memory leak happens when

    Answer: A. Memory is allocated and not released – Not releasing dynamic memory causes a memory leak.

  42. Which keyword defines a structure?

    Answer: A. struct – struct defines a structure.

  43. What must come after a class or struct definition?

    Answer: B. Semicolon – Class/struct definitions end with semicolon.

  44. Function overloading requires functions to have

    Answer: A. Same name, different parameter list – Overloaded functions share name but differ in parameter list.

  45. Can function overloading be done by return type alone?

    Answer: B. No – Return type alone is not enough for overloading.

  46. Default arguments are used when

    Answer: A. Caller omits some arguments – Default parameter values are used if caller does not pass value.

  47. A static local variable

    Answer: B. Retains value between calls – static local variable keeps its value between calls.

  48. Which header is used for file streams?

    Answer: A. <fstream> – fstream provides ifstream, ofstream and fstream.

  49. Which stream writes to a file?

    Answer: B. ofstream – ofstream is output file stream.

  50. Which stream reads from a file?

    Answer: A. ifstream – ifstream is input file stream.

  51. A class is

    Answer: A. Blueprint for objects – Class defines data and functions for objects.

  52. An object is

    Answer: A. Instance of a class – Object is created from a class.

  53. Which access specifier hides members from outside class?

    Answer: B. private – private members cannot be accessed directly outside class.

  54. Default access in a C++ class is

    Answer: B. private – Class members are private by default.

  55. Default access in a C++ struct is

    Answer: C. public – Struct members are public by default.

  56. Constructor name is same as

    Answer: B. Class name – Constructor has same name as class.

  57. Constructor return type is

    Answer: C. No return type – Constructor has no return type.

  58. Destructor name begins with

    Answer: B. ~ – Destructor name is ~ClassName.

  59. Which pointer refers to current object?

    Answer: B. this – this points to current object.

  60. Static data member belongs to

    Answer: A. Class – Static member is shared at class level.

  61. Friend function can access

    Answer: B. Private members if declared friend – friend function can access private/protected members.

  62. Inheritance supports

    Answer: A. Code reuse – Inheritance reuses and extends base class features.

  63. The class inherited from is called

    Answer: B. Base class – Base class is parent class.

  64. The inheriting class is called

    Answer: A. Derived class – Derived class inherits from base class.

  65. Which inheritance mode keeps public members public?

    Answer: C. public – Public inheritance keeps public members public.

  66. Polymorphism means

    Answer: A. Many forms – Polymorphism means one interface with many forms.

  67. Run-time polymorphism is achieved using

    Answer: A. Virtual functions – virtual functions support dynamic binding.

  68. Pure virtual function syntax includes

    Answer: A. = 0 – Pure virtual function ends with = 0.

  69. A class with pure virtual function is

    Answer: A. Abstract class – It becomes an abstract class.

  70. Operator overloading is used for

    Answer: A. User-defined meaning of operators – Operator overloading defines operator behavior for classes.

  71. Which operator cannot be overloaded?

    Answer: C. :: – Scope resolution operator :: cannot be overloaded.

  72. Templates enable

    Answer: A. Generic programming – Templates work with different data types generically.

  73. Which keyword starts a function template?

    Answer: A. template – template starts template declaration.

  74. Exception handling uses

    Answer: A. try, throw, catch – try-throw-catch handles exceptions.

  75. Which keyword throws an exception?

    Answer: B. throw – throw raises an exception.

  76. Which keyword handles an exception?

    Answer: A. catch – catch handles thrown exception.

  77. STL stands for

    Answer: A. Standard Template Library – STL means Standard Template Library.

  78. Which STL container is dynamic array?

    Answer: A. vector – vector is dynamic array.

  79. Which vector function adds element at end?

    Answer: A. push_back – push_back appends element.

  80. Which STL container stores unique sorted values?

    Answer: A. set – set stores unique sorted keys.

  81. Which STL container stores key-value pairs?

    Answer: A. map – map stores key-value pairs.

  82. Which data structure follows LIFO?

    Answer: A. Stack – Stack follows Last In First Out.

  83. Which data structure follows FIFO?

    Answer: B. Queue – Queue follows First In First Out.

  84. Which function gets top element of stack?

    Answer: C. top() – stack uses top().

  85. Which algorithm sorts a vector?

    Answer: A. sort() – sort(begin,end) sorts a range.

  86. Which header contains sort()?

    Answer: A. <algorithm> – sort is declared in <algorithm>.

  87. Which iterator points to first element?

    Answer: A. begin() – begin() returns iterator to first element.

  88. Which iterator points after the last element?

    Answer: B. end() – end() points one past last element.

  89. Range-based for loop syntax uses

    Answer: A. for(auto x : container) – C++ range-for uses colon.

  90. auto keyword is used to

    Answer: A. Let compiler infer type – auto deduces type from initializer.

  91. lambda expression is

    Answer: A. Unnamed function – Lambda is an anonymous function object.

  92. Smart pointers are available in

    Answer: A. <memory> – <memory> provides smart pointers.

  93. unique_ptr means

    Answer: A. Single ownership – unique_ptr has exclusive ownership.

  94. shared_ptr means

    Answer: A. Shared ownership – shared_ptr shares ownership through reference counting.

  95. RAII is mainly about

    Answer: A. Resource management through object lifetime – RAII ties resource release to object destruction.

  96. binary_search requires range to be

    Answer: A. Sorted – binary_search expects sorted range.

  97. Which function reverses a range?

    Answer: A. reverse() – reverse(begin,end) reverses order.

  98. Which program design is best for a student management project?

    Answer: A. Use classes and file handling – Classes and files make project organized.

  99. Encapsulation means

    Answer: A. Wrapping data and methods together with controlled access – Encapsulation protects data inside class.

  100. Abstraction means

    Answer: A. Showing essential details and hiding internal complexity – Abstraction hides implementation details.

  101. Which concept represents is-a relationship?

    Answer: A. Inheritance – Inheritance models is-a relationship.

  102. Which concept represents has-a relationship?

    Answer: A. Composition – Composition models has-a relationship.

  103. What is dangling pointer?

    Answer: A. Pointer pointing to invalid/freed memory – Dangling pointer points to memory that is no longer valid.

  104. Which is safer in modern C++?

    Answer: A. Smart pointer – Smart pointers reduce memory management errors.

  105. Which cast is preferred for normal explicit conversion?

    Answer: A. static_cast – static_cast is preferred for well-defined conversions.

  106. Which value prints for bool true by default using cout?

    Answer: B. 1 – cout prints true as 1 unless boolalpha is used.

  107. Which manipulator prints bool as true/false text?

    Answer: A. boolalpha – boolalpha changes bool output formatting.

  108. Which manipulator sets decimal precision?

    Answer: A. setprecision – setprecision is from <iomanip>.

  109. Which header is needed for setprecision?

    Answer: A. <iomanip> – iomanip contains formatting manipulators.

  110. Which operator accesses class member through object?

    Answer: A. . – Dot operator accesses member using object.

  111. Which operator accesses member through pointer?

    Answer: B. -> – Arrow operator accesses member through pointer.

  112. Which operator is scope resolution?

    Answer: A. :: – :: is scope resolution operator.

  113. Which keyword prevents overriding when used on virtual function in derived class?

    Answer: A. final – final prevents further overriding.

  114. Which keyword clearly marks overriding function?

    Answer: A. override – override tells compiler function should override a base virtual function.

  115. Which container adaptor gives highest priority element first by default?

    Answer: A. priority_queue – priority_queue returns highest priority element first by default.

  116. Which pair member stores first value?

    Answer: A. first – pair uses first and second.

  117. Which pair member stores second value?

    Answer: B. second – pair second stores second value.

  118. Which STL container is best for fast key lookup with sorted keys?

    Answer: A. map – map keeps keys sorted and supports lookup.

  119. Which container can store duplicates in sorted order?

    Answer: A. multiset – multiset allows duplicate sorted values.

  120. Which keyword defines a type alias in modern C++?

    Answer: A. using – using can create type aliases.

← Back to C++ Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

यह lesson कैसा लगा?

आपकी राय से हम content और बेहतर बनाते हैं।

अपना review और सुझाव लिखें (वैकल्पिक)

Review approve होने के बाद आपका नाम और शहर इसके साथ public दिख सकते हैं। Email या phone न लिखें।

▶ CodingEasily on YouTube

Video से सीखें – आसान Hindi में

चुनी हुई video: RDBMS भाग 3 – Class XI Commerce IT

▶ Channel subscribe करें