read this code: 200+ C++ Programming MCQs | PCBooks - Master C++ Language Online

C++ - Programming MCQ Questions and Answers

Test your knowledge of Microsoft Word with these interactive multiple-choice questions.

« First 5 6 7 8 Last »
« Previous Page Next Page »

101. Which of these is not a valid C++ bitwise operator?

  • a) &
  • b) |
  • c) ^
  • d) %
Answer: D - % is the modulus operator, not a bitwise operator.

102. What is the correct syntax to declare a specialization of a class template?

  • a) template<> class MyClass<int> { };
  • b) class MyClass<int> { };
  • c) template<int> class MyClass { };
  • d) template class MyClass<int>;
Answer: A - Explicit specialization requires template<> prefix.

103. Which of the following is true about static polymorphism?

  • a) Achieved through virtual functions
  • b) Resolved at compile time
  • c) Requires runtime type information
  • d) Uses dynamic binding
Answer: B - Static polymorphism (templates, overloading) is resolved at compile time.

104. What is the output of: cout << (1 << 3);

  • a) 1
  • b) 3
  • c) 8
  • d) 9
Answer: C - Left shift by 3 multiplies 1 by 2³ (8).

105. Which of these is not a valid C++20 feature?

  • a) Three-way comparison (spaceship operator)
  • b) std::format
  • c) std::generator
  • d) Concepts
Answer: C - std::generator is not in C++20 (planned for C++23).

106. What is the purpose of the 'requires' clause?

  • a) To specify template constraints
  • b) To mark functions as mandatory
  • c) To enforce exception specifications
  • d) To declare abstract methods
Answer: A - requires specifies constraints for templates (C++20 concepts).

107. Which STL container provides LIFO ordering?

  • a) queue
  • b) stack
  • c) deque
  • d) priority_queue
Answer: B - stack provides Last-In-First-Out (LIFO) ordering.

108. What is the correct way to declare a user-defined literal?

  • a) double operator"" _km(double);
  • b) double _km operator""(double);
  • c) operator"" double _km(double);
  • d) literal double _km(double);
Answer: A - User-defined literals use operator"" followed by the suffix.

109. Which of these is not a valid C++ type conversion?

  • a) static_cast
  • b) dynamic_cast
  • c) safe_cast
  • d) reinterpret_cast
Answer: C - safe_cast is not a standard C++ cast (it's from C++/CLI).

110. What is the output of: cout << sizeof(long double);

  • a) 4
  • b) 8
  • c) 10
  • d) Implementation defined
Answer: D - long double size varies by implementation (often 10-16 bytes).

111. Which of these is not a valid C++17 feature?

  • a) Structured bindings
  • b) if constexpr
  • c) std::optional
  • d) std::jthread
Answer: D - std::jthread was introduced in C++20.

112. What is the purpose of the '[[carries_dependency]]' attribute?

  • a) To mark exception-prone code
  • b) To propagate dependency chains in relaxed memory models
  • c) To indicate thread safety
  • d) To optimize return value storage
Answer: B - It helps optimize dependency chains in low-level concurrency code.

113. Which STL algorithm is used to find the first mismatch between ranges?

  • a) std::find
  • b) std::search
  • c) std::mismatch
  • d) std::compare
Answer: C - std::mismatch finds the first position where two ranges differ.

114. What is the correct way to declare a template template parameter?

  • a) template<template<typename> typename T>
  • b) template<typename template<typename> T>
  • c) template<template T<typename>>
  • d) template<typename T<typename>>
Answer: A - template<template<typename> typename T> is the correct syntax.

115. Which of these is not a valid C++14 feature?

  • a) Return type deduction for normal functions
  • b) Variable templates
  • c) Generic lambdas
  • d) std::expected
Answer: D - std::expected is not in C++14 (proposed for C++23).

116. What is the output of: cout << (true + false);

  • a) 0
  • b) 1
  • c) true
  • d) Compilation error
Answer: B - true converts to 1, false to 0 (1+0=1).

117. Which of these is not a valid C++ string view operation?

  • a) substr
  • b) find
  • c) append
  • d) compare
Answer: C - string_view is read-only and doesn't support append.

118. What is the purpose of the '[[noreturn]]' attribute?

  • a) To indicate a function doesn't return to its caller
  • b) To disable return value optimization
  • c) To mark functions that throw exceptions
  • d) To prevent tail-call optimization
Answer: A - Used for functions like exit() or throw that don't return.

119. Which STL algorithm is used to replace elements?

  • a) std::change
  • b) std::replace
  • c) std::swap
  • d) std::assign
Answer: B - std::replace replaces all occurrences of a value in a range.

120. What is the correct way to declare a fold expression?

  • a) (args + ...)
  • b) ... + args
  • c) fold(args +)
  • d) args fold(+)
Answer: A - Fold expressions use (pack op ...) or (... op pack) syntax.
« First 5 6 7 8 Last »
« Previous Page Next Page »

Learn Computer Skills with PCBooks

Master computer skills with PCBooks! Explore interactive tutorials, MCQ tests, and online exams for programming, web development, and IT fundamentals. Perfect for beginners and advanced learners.

Online MCQ Tests for Programming

Practice programming MCQ questions and improve your coding skills with our online quizzes. Whether you're learning Python, Java, or C programming, PCBooks has you covered.

Free Web Development Tutorials

Learn HTML, CSS, and JavaScript with our free web development tutorials. Test your knowledge with interactive quizzes and online exams.