121. Which of these is not a valid C++ comparison operator?
Answer: B - <> is not a valid operator in C++ (it's used in some other languages).
122. What is the correct syntax to declare a deduction guide for a constructor?
- a) template<typename T> MyClass(T) -> MyClass<T>;
- b) MyClass template<T>(T) -> MyClass<T>;
- c) deduce MyClass(T) -> MyClass<T>;
- d) template<T> deduce MyClass(T) -> MyClass<T>;
Answer: A - Deduction guides follow template declaration syntax.
123. Which of the following is true about constexpr functions?
- a) They must be evaluated at compile time
- b) They can only call other constexpr functions
- c) They can be evaluated at either compile time or runtime
- d) They cannot have side effects
Answer: C - constexpr functions can be evaluated at either time (since C++14).
124. What is the output of: cout << (3.5 + 2);
- a) 5
- b) 5.5
- c) 6
- d) Compilation error
Answer: B - The int is promoted to double (3.5 + 2.0 = 5.5).
125. Which of these is not a valid C++20 feature?
- a) std::span
- b) std::jthread
- c) std::generator
- d) std::source_location
Answer: C - std::generator is not in C++20 (planned for C++23).
126. What is the purpose of the '[[likely]]' and '[[unlikely]]' attributes?
- a) To mark exception-prone code paths
- b) To indicate branch prediction hints
- c) To enforce inlining decisions
- d) To disable certain optimizations
Answer: B - They provide branch prediction hints to the compiler.
127. Which STL container provides FIFO ordering?
- a) stack
- b) queue
- c) priority_queue
- d) deque
Answer: B - queue provides First-In-First-Out (FIFO) ordering.
128. What is the correct way to declare a nested class?
- a) class Outer { class Inner { }; };
- b) class Outer::Inner { };
- c) nested class Outer::Inner { };
- d) Both a and b
Answer: D - Both syntaxes are valid (second requires Outer to be complete).
129. Which of these is not a valid C++ type trait?
- a) std::is_aggregate
- b) std::is_standard_layout
- c) std::is_function_pointer
- d) std::is_callable
Answer: D - is_callable is not a standard type trait (use is_invocable).
130. What is the output of: cout << sizeof(std::vector<int>);
- a) 4
- b) 8
- c) 12
- d) Implementation defined
Answer: D - vector size depends on implementation (typically 12-24 bytes).
131. 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.
132. 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.
133. Which STL algorithm is used to rotate elements?
- a) std::shift
- b) std::rotate
- c) std::swap_ranges
- d) std::permute
Answer: B - std::rotate performs a left rotation on a range.
134. What is the correct way to declare a variable template?
- a) template<typename T> T constant = T(1.0);
- b) variable template<T> T constant = T(1.0);
- c) template T constant<typename T> = T(1.0);
- d) T template constant<typename T> = T(1.0);
Answer: A - Variable templates use standard template syntax.
135. Which of these is not a valid C++14 feature?
- a) Binary literals
- b) Digit separators
- c) Generic lambdas
- d) std::format
Answer: D - std::format was introduced in C++20.
136. What is the output of: cout << (10.0 / 3);
- a) 3
- b) 3.33333
- c) 3.0
- d) 4
Answer: B - Floating-point division preserves fractional part.
137. Which of these is not a valid C++ chrono duration?
- a) std::chrono::nanoseconds
- b) std::chrono::microseconds
- c) std::chrono::milliseconds
- d) std::chrono::centiseconds
Answer: D - centiseconds is not a predefined duration.
138. What is the purpose of the '[[deprecated]]' attribute?
- a) To mark obsolete features
- b) To disable compiler optimizations
- c) To indicate thread-unsafe code
- d) To prevent inlining
Answer: A - It marks features that may be removed in future versions.
139. Which STL algorithm is used to generate values?
- a) std::fill
- b) std::generate
- c) std::create
- d) std::make
Answer: B - std::generate assigns values from a generator function.
140. What is the correct way to declare a template alias?
- a) template<typename T> using Vec = std::vector<T>;
- b) template alias Vec<T> = std::vector<T>;
- c) alias template<T> Vec = std::vector<T>;
- d) template Vec<typename T> = std::vector<T>;
Answer: A - Template aliases use 'using' keyword with template parameters.