141. Which of these is not a valid C++ arithmetic operator?
Answer: D - × is not a valid operator (use * for multiplication).
142. What is the correct syntax to declare a partial template specialization?
- a) template<typename T> class MyClass<T*> { };
- b) template<typename T*> class MyClass { };
- c) class MyClass<typename T*> { };
- d) template<*T> class MyClass { };
Answer: A - Partial specialization keeps some template parameters generic.
143. Which of the following is true about std::atomic?
- a) It guarantees thread safety for all operations
- b) It prevents compiler optimizations
- c) It provides lock-free operations when possible
- d) It cannot be used with built-in types
Answer: C - std::atomic uses lock-free operations when supported by the hardware.
144. What is the output of: cout << (1 << 4);
Answer: D - Left shift by 4 multiplies 1 by 2⁴ (16).
145. Which of these is not a valid C++20 feature?
- a) std::format
- b) std::jthread
- c) std::generator
- d) std::source_location
Answer: C - std::generator is not in C++20 (planned for C++23).
146. What is the purpose of the '[[no_unique_address]]' attribute?
- a) To allow empty base optimization for data members
- b) To prevent address-taking operations
- c) To mark singleton classes
- d) To disable RTTI for a class
Answer: A - It enables EBO for non-static data members.
147. Which STL container provides constant-time insertion at both ends?
- a) vector
- b) list
- c) deque
- d) array
Answer: C - deque (double-ended queue) provides O(1) insertion at both ends.
148. What is the correct way to declare a user-defined conversion operator?
- a) operator int() const;
- b) int operator() const;
- c) convert int() const;
- d) operator() int const;
Answer: A - Conversion operators use operator type() syntax.
149. Which of these is not a valid C++ type trait?
- a) std::is_polymorphic
- b) std::is_abstract
- c) std::is_functional
- d) std::is_final
Answer: C - is_functional is not a standard type trait.
150. What is the output of: cout << sizeof(std::function<void()>);
- a) 4
- b) 8
- c) 16
- d) Implementation defined
Answer: D - std::function size depends on implementation (typically 32-64 bytes).
151. Which of these is not a valid C++17 feature?
- a) if constexpr
- b) Structured bindings
- c) std::optional
- d) std::syncstream
Answer: D - std::syncstream was introduced in C++20.
152. What is the purpose of the '[[nodiscard]]' attribute?
- a) To prevent function inlining
- b) To warn when return value is ignored
- c) To disable return value optimization
- d) To mark functions as pure
Answer: B - [[nodiscard]] warns if a function's return value is ignored.
153. Which STL algorithm is used to find adjacent duplicates?
- a) std::find
- b) std::search
- c) std::adjacent_find
- d) std::unique
Answer: C - std::adjacent_find finds first adjacent equal elements.
154. 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.
155. 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).
156. What is the output of: cout << (true + true);
Answer: C - true converts to 1 (1+1=2).
157. Which of these is not a valid C++ string operation?
- a) substr
- b) find
- c) append
- d) join
Answer: D - join is not a member function (available in some libraries).
158. 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.
159. 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.
160. 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.