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 7 8 9 10 Last »
« Previous Page Next Page »

181. Which of these is not a valid C++ operator associativity?

  • a) Right-to-left for assignment
  • b) Left-to-right for addition
  • c) Right-to-left for ternary operator
  • d) Left-to-right for scope resolution
Answer: D - Scope resolution (::) has no associativity (not a binary operator).

182. What is the correct syntax for a requires clause in C++20?

  • a) template<typename T> requires std::integral<T>
  • b) template<typename T> where std::integral<T>
  • c) template<typename T> if std::integral<T>
  • d) template<typename T> assert std::integral<T>
Answer: A - The 'requires' keyword introduces constraints.

183. Which of these is not true about std::source_location?

  • a) Provides file name information
  • b) Provides line number information
  • c) Can be used as a function default argument
  • d) Requires compiler support
Answer: C - Cannot be used as default argument (must use current()).

184. What is the output of: cout << (5 | 3);

  • a) 1
  • b) 7
  • c) 8
  • d) 15
Answer: B - Bitwise OR of 5 (101) and 3 (011) is 7 (111).

185. Which of these is not a valid C++23 feature?

  • a) std::stacktrace
  • b) std::print
  • c) std::generator
  • d) std::networking
Answer: D - Networking was postponed from C++23.

186. What is the purpose of the '[[assume]]' attribute in C++23?

  • a) To mark code assumptions for optimization
  • b) To indicate thread safety
  • c) To enforce exception specifications
  • d) To declare abstract methods
Answer: A - Allows programmers to express assumptions to the optimizer.

187. Which STL container provides O(1) amortized insertion at end?

  • a) std::list
  • b) std::vector
  • c) std::map
  • d) std::set
Answer: B - vector provides amortized constant time push_back().

188. What is the correct way to declare a coroutine return type?

  • a) std::coroutine_handle<>
  • b) A type satisfying the Promise requirements
  • c) std::future
  • d) Any type with co_await operator
Answer: B - Must satisfy the Promise requirements (usually via generator type).

189. Which of these is not a valid C++ memory model operation?

  • a) load
  • b) store
  • c) fence
  • d) barrier
Answer: D - "barrier" is not a standard term (use "fence").

190. What is the output of: cout << sizeof(std::variant<int, double>);

  • a) 4
  • b) 8
  • c) 12
  • d) Implementation defined
Answer: D - Depends on alignment requirements (typically max(sizeof(T)) + overhead.

191. Which of these is not a valid C++20 ranges view?

  • a) views::filter
  • b) views::transform
  • c) views::map
  • d) views::take
Answer: C - views::map doesn't exist (use views::transform).

192. What is the purpose of the '[[unlikely]]' attribute?

  • a) To mark exception-prone code
  • b) To indicate unlikely code paths for optimization
  • c) To prevent inlining
  • d) To disable optimizations
Answer: B - Helps compiler optimize branch prediction.

193. Which STL algorithm is used to check if all elements satisfy a condition?

  • a) std::any_of
  • b) std::all_of
  • c) std::none_of
  • d) std::find_if
Answer: B - std::all_of checks if all elements meet a predicate.

194. What is the correct way to declare a nested concept?

  • a) template<typename T> concept Nested = requires { typename T::type; };
  • b) concept Nested<typename T> = requires { typename T::type; };
  • c) nested concept Nested = requires(T) { typename T::type; };
  • d) concept Nested = typename T::type;
Answer: A - Concepts follow template-style declaration syntax.

195. Which of these is not a valid C++23 feature?

  • a) std::mdspan
  • b) std::expected
  • c) std::generator
  • d) std::networking
Answer: D - Networking was postponed from C++23.

196. What is the output of: cout << (10 % 3.0);

  • a) 1
  • b) 1.0
  • c) Compilation error
  • d) Runtime error
Answer: C - % cannot be used with floating-point operands.

197. Which of these is not a valid C++ chrono duration cast?

  • a) std::chrono::duration_cast
  • b) std::chrono::floor
  • c) std::chrono::round
  • d) std::chrono::approximate
Answer: D - "approximate" is not a valid duration cast operation.

198. What is the purpose of the '[[nodiscard]]' attribute?

  • a) To mark functions whose return value should not be ignored
  • b) To disable return value optimization
  • c) To indicate pure functions
  • d) To prevent inlining
Answer: A - Warns when function return value is discarded.

199. Which STL algorithm is used to merge sorted ranges?

  • a) std::merge
  • b) std::concat
  • c) std::join
  • d) std::combine
Answer: A - std::merge combines two sorted ranges into one sorted range.

200. What is the correct way to declare a requires expression?

  • a) requires (T t) { t.f(); }
  • b) requires T { void f(); }
  • c) template requires T { t.f(); }
  • d) concept requires = T.f();
Answer: A - Requires expressions use 'requires' followed by parameter list and requirements.
« First 7 8 9 10 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.