61. Which of these is not a valid C++ relational operator?
Answer: C - => is not a valid operator in C++ (=> is used in some other languages).
62. What is the correct syntax to declare a class template?
- a) template<class T> class MyClass { };
- b) class template<T> MyClass { };
- c) template MyClass<class T> { };
- d) class MyClass template<T> { };
Answer: A - The correct syntax is template<class T> followed by class definition.
63. Which of the following is true about virtual functions?
- a) They must be defined in the base class
- b) They cannot be private
- c) They enable runtime polymorphism
- d) They cannot be overridden
Answer: C - Virtual functions enable runtime polymorphism through function overriding.
64. What is the output of: cout << (5 ^ 3);
Answer: A - Bitwise XOR of 5 (101) and 3 (011) is 6 (110).
65. Which of these is not a valid C++20 feature?
- a) Concepts
- b) Modules
- c) Ranges
- d) Properties
Answer: D - Properties are not part of standard C++20 (they exist in some other languages).
66. What is the purpose of the 'noexcept' specifier?
- a) To indicate a function won't throw exceptions
- b) To prevent exception handling
- c) To optimize try-catch blocks
- d) To create new exception types
Answer: A - noexcept indicates a function doesn't throw exceptions, enabling optimizations.
67. Which STL container provides fastest 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.
68. What is the correct way to declare a move assignment operator?
- a) ClassName& operator=(ClassName other)
- b) ClassName& operator=(const ClassName& other)
- c) ClassName& operator=(ClassName&& other)
- d) void operator=(ClassName other)
Answer: C - Move assignment takes an rvalue reference (&&) and returns a reference.
69. Which of these is not a valid C++ storage duration?
- a) Automatic
- b) Static
- c) Thread
- d) Persistent
Answer: D - Persistent is not a standard C++ storage duration.
70. What is the output of: cout << sizeof(nullptr);
- a) 1
- b) 2
- c) 4
- d) Same as sizeof(void*)
Answer: D - nullptr is a pointer literal, so its size matches pointer size.
71. Which of these is not a valid C++11 feature?
- a) Range-based for loops
- b) Lambda expressions
- c) Structured bindings
- d) nullptr
Answer: C - Structured bindings were introduced in C++17.
72. What is the purpose of the 'alignas' specifier?
- a) To align memory allocations
- b) To compare alignment of types
- c) To create aligned arrays
- d) To specify minimum alignment requirement
Answer: D - alignas specifies minimum alignment requirement for types/variables.
73. Which STL algorithm is used to partition elements?
- a) std::sort
- b) std::partition
- c) std::group
- d) std::divide
Answer: B - std::partition rearranges elements based on a predicate.
74. What is the correct way to declare a thread-local variable?
- a) thread_local int x;
- b) local_thread int x;
- c) int thread_local x;
- d) Both a and c
Answer: D - thread_local can appear before or after the type specifier.
75. Which of these is not a valid C++17 feature?
- a) Structured bindings
- b) std::variant
- c) std::optional
- d) Modules
Answer: D - Modules were introduced in C++20.
76. What is the output of: cout << (5 << 1);
Answer: C - Left shift by 1 multiplies by 2 (5*2=10).
77. Which of these is not a valid C++ container adapter?
- a) stack
- b) queue
- c) priority_queue
- d) heap
Answer: D - heap is an algorithm, not a container adapter.
78. What is the purpose of the 'constexpr' keyword?
- a) To declare constant expressions
- b) To evaluate expressions at compile time
- c) To define functions that can be evaluated at compile time
- d) All of the above
Answer: D - constexpr enables compile-time evaluation of variables/functions.
79. Which STL algorithm is used to transform elements?
- a) std::change
- b) std::transform
- c) std::map
- d) std::convert
Answer: B - std::transform applies an operation to a range of elements.
80. What is the correct way to declare a variadic template?
- a) template<typename... Args>
- b) template<typename Args...>
- c) template<...typename Args>
- d) template<variadic typename Args>
Answer: A - The ellipsis comes after typename/class and before the parameter pack name.