1 What is the function of 'std::clamp(val, low, high)' introduced in C++17 (<algorithm>)? A It clamps a mutex to prevent re-locking B It rounds a float to the nearest integer C It computes the absolute value D It clamps val within the range [low, high]: returns low if val < low, high if val > high, or val otherwise
View answer & explanationFull Screen Mode →
2 What does 'std::packaged_task<R(Args...)>' do in C++11 (<future>)? A It packages variables into a binary archive B It bundles multiple threads into a thread pool C It wraps any callable target (function, lambda, functor) so that it can be invoked asynchronously, storing its return value or thrown exception in an associated std::future D It compresses network packets
View answer & explanationFull Screen Mode →
3 What is a 'Spurious Wakeup' prevented by in modern C++ condition variables? A Using recursive mutexes B Passing a predicate lambda to wait(): cv.wait(lock, [&]{ return ready; }); C Setting thread priority to maximum D Disabling interrupts
View answer & explanationFull Screen Mode →
4 What does the C++20 uniform container erasure function 'std::erase(vec, val)' do? A It directly performs the Erase-Remove idiom in a single call, erasing all elements equal to val and resizing the container B It only removes the first element equal to val C It clears the entire container D It returns a copy of the container without val
View answer & explanationFull Screen Mode →
5 What is the return value of 'std::remove' in the STL algorithm library (the Erase-Remove Idiom)? A void B The number of elements deleted C A boolean indicating if elements were found D An iterator to the new past-the-end element of the shortened range (it does NOT delete elements or change vector size; vector.erase() must be called to actually shrink the container)
View answer & explanationFull Screen Mode →
6 What is the difference between 'std::set' and 'std::unordered_set' regarding iterator ordering? A std::set iterators can modify keys B std::unordered_set iterators are bidirectional C std::set iterators traverse elements in strictly ascending sorted order; std::unordered_set iterators traverse elements in arbitrary bucket hash order D There is no difference in ordering
View answer & explanationFull Screen Mode →
7 What is 'std::visit' used for in modern C++? A Traversing all nodes in a binary tree B Applying a callable visitor (like an overloaded lambda) to the current active value inside a std::variant C Visiting all files in a directory D Iterating over a vector
View answer & explanationFull Screen Mode →
8 What is 'std::optional' introduced in C++17 (<optional>)? A A vocabulary type that represents a value that may or may not be present (nullopt), eliminating the use of sentinel values like -1 or null pointers B A function parameter with a default value C An optional library feature D A pointer to an optional class
View answer & explanationFull Screen Mode →
9 What is 'std::variant' introduced in C++17 (<variant>)? A An array of variable sizes B A variable that changes type dynamically at runtime like in JavaScript C A pointer that can point to any class D A type-safe, union-like container that holds a value of one of several specified alternative types at any given time, managed without heap allocation
View answer & explanationFull Screen Mode →
10 What is 'std::any' introduced in C++17 (<any>)? A A void pointer wrapper without type checks B A template type that matches all parameters C A type-safe container for single values of any copy-constructible type, throwing std::bad_any_cast if extracted with the wrong type D A boolean function that checks if any elements match a condition
View answer & explanationFull Screen Mode →
11 What is the output of the following C++ code snippet?
std::vector<int> v = {1, 2, 3};
v.erase(v.begin() + 1);
std::cout << v.size() << " " << v[1]; A 2 2 B 2 3 C 3 3 D 2 1
View answer & explanationFull Screen Mode →
12 What is an 'atomic flag' (std::atomic_flag) in C++11? A The only atomic boolean type guaranteed by the C++ standard to be completely lock-free on all architectures, supporting test_and_set() and clear() B A compiler flag passed to g++ C A thread that runs with maximum priority D A volatile boolean
View answer & explanationFull Screen Mode →
13 What is the return value of 'std::set::insert(val)' in C++? A void B A boolean indicating success C An iterator to the inserted element D A std::pair<iterator, bool>, where the iterator points to the element, and the bool indicates whether the insertion took place (true) or if the element already existed (false)
View answer & explanationFull Screen Mode →
14 What is the difference between 'std::stack' and 'std::queue'? A std::stack can be sorted, std::queue cannot B std::stack is FIFO, std::queue is LIFO C std::stack is a LIFO (Last-In-First-Out) container adapter; std::queue is a FIFO (First-In-First-Out) container adapter D std::stack supports random access
View answer & explanationFull Screen Mode →
15 What is the purpose of 'std::transform' in the C++ algorithm library? A It converts classes between inheritance levels B It applies an unary or binary function to a range of input elements and writes the results to a destination range (the C++ equivalent of 'map') C It rotates elements in an array D It transforms strings into integers
View answer & explanationFull Screen Mode →
16 What is the behavior of 'std::string::c_str()' versus 'std::string::data()' in modern C++? A Both return a pointer to a null-terminated character array (since C++11, data() is guaranteed to be null-terminated just like c_str()) B c_str() is null-terminated, but data() is never null-terminated C c_str() allocates new memory, data() does not D data() returns a void pointer
View answer & explanationFull Screen Mode →
17 What is the difference between 'std::set::erase(iterator)' and 'std::set::erase(value)'? A Both have O(n) time complexity B erase(iterator) removes all elements C erase(value) throws an exception if the key is not found D erase(iterator) removes the element at that exact position in O(1) amortized time; erase(value) searches for the key in O(log n) time and returns the number of elements removed (0 or 1)
View answer & explanationFull Screen Mode →
18 What are the Parallel Execution Policies introduced in C++17 (<execution>)? A std::cpu, std::gpu, and std::tpu B std::async, std::thread, and std::future C std::execution::seq (sequential), std::execution::par (parallel), and std::execution::par_unseq (parallel and vectorized/SIMD) D std::fast, std::normal, and std::slow
View answer & explanationFull Screen Mode →
19 What is the difference between 'std::find' and 'std::binary_search'? A std::find only works on integers B std::find performs a linear scan O(n) on unsorted ranges and returns an iterator; std::binary_search requires a SORTED range, runs in O(log n), and returns a boolean (true/false) C std::binary_search returns an iterator to the found element D std::find is faster than binary_search
View answer & explanationFull Screen Mode →
20 What is 'std::accumulate' in <numeric>, and what is its default binary operation? A It accumulates the values in a range by applying addition (operator+) starting with a specified initial value B It finds the maximum element in a range C It multiplies all elements together D It calculates the average
View answer & explanationFull Screen Mode →
21 What is the relationship between 'std::promise' and 'std::future' in C++11? A std::promise is used for mutex locking B std::promise runs the thread, while future sleeps C They are identical types D std::promise is the 'producer' that sets a value or exception, and std::future is the 'consumer' that reads the value asynchronously
View answer & explanationFull Screen Mode →
22 What happens when 'std::future::get()' is called? A It cancels the asynchronous task B It polls the result non-blockingly and returns a boolean C It blocks the calling thread until the asynchronous result is ready, retrieves the value, and invalidates the future (it can be called only once) D It copies the future to a new thread
View answer & explanationFull Screen Mode →
23 What is 'std::async' in C++11 (<future>)? A A keyword to declare asynchronous classes B A high-level task-based concurrency function that runs a callable object (potentially on an asynchronous background thread) and returns an std::future to retrieve the result C A replacement for std::mutex D A coroutine executor
View answer & explanationFull Screen Mode →
24 What is the default memory ordering used by operations on 'std::atomic<T>' when no memory order argument is passed? A std::memory_order_seq_cst (Sequential Consistency, providing the strictest total global ordering of operations across all threads) B std::memory_order_relaxed C std::memory_order_acquire D std::memory_order_release
View answer & explanationFull Screen Mode →
25 What is 'std::shared_mutex' introduced in C++17 (<shared_mutex>)? A A lock-free queue B A mutex shared across multiple operating system processes C A mutex managed by std::shared_ptr D A Reader-Writer Lock allowing multiple threads to hold a shared read lock (lock_shared()) concurrently, or a single thread to hold an exclusive write lock (lock())
View answer & explanationFull Screen Mode →
26 What is a 'Spurious Wakeup' in condition variables (std::condition_variable), and how is it handled in C++? A A signal sent by the operating system to abort the thread B A crash caused by thread interruption C A thread waiting on a condition variable waking up even though no other thread notified it; it is handled by waiting in a loop with a predicate: cv.wait(lock, [&]{ return condition; }); D A memory corruption bug in mutexes
View answer & explanationFull Screen Mode →
27 What is the difference between 'std::mutex' and 'std::recursive_mutex'? A recursive_mutex is faster than mutex B A std::recursive_mutex can be locked multiple times by the SAME thread without causing a deadlock (requiring an equal number of unlocks); locking a standard std::mutex twice on the same thread causes undefined behavior/deadlock C recursive_mutex can be shared across processes D mutex allows multiple writers
View answer & explanationFull Screen Mode →
28 What is a 'Data Race' in C++ multithreading, and what is its standard consequence? A Two or more concurrent threads accessing the same memory location where at least one access is a write, without synchronization; it constitutes Undefined Behavior B Two threads trying to lock the same mutex C A thread running faster than another thread D An exception thrown across a thread boundary
View answer & explanationFull Screen Mode →
29 How does 'std::jthread' introduced in C++20 (<thread>) improve upon 'std::thread'? A std::jthread eliminates data races automatically B std::jthread runs on the GPU C std::jthread creates green threads (fibers) D std::jthread automatically requests cooperative stop/cancellation and calls join() in its destructor (RAII compliant), preventing std::terminate crashes
View answer & explanationFull Screen Mode →
30 What happens if a 'std::thread' object is destroyed while it is still 'joinable' (neither joined nor detached)? A The thread is automatically detached B The thread is automatically joined C The std::thread destructor calls std::terminate(), crashing the program D The thread is killed silently
View answer & explanationFull Screen Mode →
31 What is the effect of calling 'std::thread::detach()' on a thread object? A It pauses the thread indefinitely B It separates the thread of execution from the std::thread object, allowing it to continue running independently in the background; the std::thread object becomes non-joinable C It terminates the thread immediately D It kills the parent process
View answer & explanationFull Screen Mode →
32 Which STL container iterators satisfy the 'Contiguous Iterator' concept introduced in C++20? A std::vector, std::array, std::string, and std::span B std::deque and std::list C std::map and std::set D std::unordered_map
View answer & explanationFull Screen Mode →
33 What are the six standard C++ iterator categories ordered from least powerful to most powerful? A Read, Write, Seek, Stream, Block, and Buffer B Forward, Backward, Linear, Random, Continuous, and Discrete C Pointer, Reference, Array, Map, Stack, and Queue D Input, Output, Forward, Bidirectional, Random Access, and Contiguous
View answer & explanationFull Screen Mode →
34 What is the difference between 'std::set' and 'std::multiset'? A std::set is a hash table, while std::multiset is a tree B std::set is unsorted, while std::multiset is sorted C std::set stores unique keys only; std::multiset permits multiple duplicate keys with equivalent values D std::multiset has thread-safe operations
View answer & explanationFull Screen Mode →
35 What happens if a key is accessed in a std::map using 'map.at(key)' when the key does NOT exist in the map? A It inserts the key with a default value B It throws a std::out_of_range exception C It returns nullptr D It returns 0 silently
View answer & explanationFull Screen Mode →
36 What happens if a key is accessed in a std::map using the subscript operator (map[key]) when the key does NOT exist in the map? A It automatically default-constructs and inserts a new key-value pair with that key, and returns a reference to the newly created value B It throws a std::out_of_range exception C It returns a null pointer D It causes undefined behavior / segmentation fault
View answer & explanationFull Screen Mode →
37 What is the 'Load Factor' of a std::unordered_map, and what happens when it exceeds the 'max_load_factor'? A It deletes the oldest elements automatically B Load factor is the percentage of RAM consumed C It causes a std::out_of_range exception D Load factor is the ratio of elements to buckets (size / bucket_count); when it exceeds max_load_factor (default 1.0), the container automatically triggers 'rehashing' (allocating more buckets and redistributing elements)
View answer & explanationFull Screen Mode →
38 What is the difference between 'std::list' and 'std::forward_list'? A std::forward_list can only store integers B std::list is contiguous, while forward_list is not C std::list is a doubly-linked list (supporting bidirectional traversal); std::forward_list is a singly-linked list (supporting only forward traversal and saving memory by storing only one pointer per node) D std::forward_list supports random access indexing [ ]
View answer & explanationFull Screen Mode →
39 What is the underlying data structure of the 'std::priority_queue' container adapter by default? A A sorted doubly-linked list B A Max-Heap implemented on top of a std::vector using std::make_heap, std::push_heap, and std::pop_heap C A Red-Black binary search tree D A circular ring buffer
View answer & explanationFull Screen Mode →
40 Why is 'std::vector<bool>' notorious in the C++ community? A It is a specialized proxy container that packs booleans into individual bits (1 bit per bool), meaning its operator[] returns a proxy object (std::vector<bool>::reference) rather than a real 'bool&', violating container requirements B It cannot hold more than 64 booleans C It is slower than std::list<bool> for all operations D It causes memory leaks on destruction
View answer & explanationFull Screen Mode →
41 What is the difference between 'std::vector' and 'std::deque' in internal memory organization? A std::deque allocates all memory on the stack B std::vector is a linked list, std::deque is an array C std::deque does not support random access indexing operator[] D std::vector stores elements in a single contiguous memory block; std::deque stores elements in a series of fixed-size chunks (paged memory) managed by a central map of chunk pointers
View answer & explanationFull Screen Mode →
42 What does the 'noexcept(expression)' operator (used as an operator, not a specifier) evaluate to at compile time? A The size of the exception table B A runtime check of CPU status C A compile-time boolean constant that is true if the compiler can verify that the expression is guaranteed not to throw any exceptions, and false otherwise D A pointer to the exception handler
View answer & explanationFull Screen Mode →
43 What does the 'noexcept' specifier on a function declaration (e.g. void f() noexcept;) guarantee? A It automatically catches all exceptions inside the function body B It guarantees that the function will not throw any exceptions; if an exception does escape a noexcept function, std::terminate() is invoked immediately without unwinding the stack C It turns all exceptions into error return codes D It prevents the function from calling any other functions
View answer & explanationFull Screen Mode →
44 What happens if an active exception is unhandled and reaches the end of main()? A std::terminate() is called, which by default calls std::abort() to terminate the process abnormally B The program restarts from main() C The exception is printed to std::cerr and the program exits with code 0 D The operating system ignores it
View answer & explanationFull Screen Mode →
45 Why should exceptions always be caught by reference ('catch (const std::exception& e)') rather than by value ('catch (std::exception e)')? A Catching by reference converts the exception to an integer B Catching by reference causes memory leaks C Catching by value is forbidden by the compiler D Catching by value causes Object Slicing (slicing off derived exception information and breaking polymorphic e.what() calls) and introduces unnecessary copy overhead
View answer & explanationFull Screen Mode →
46 What is the difference between 'std::lower_bound' and 'std::upper_bound' on a sorted range? A lower_bound is O(n), upper_bound is O(log n) B lower_bound returns the smallest element, upper_bound returns the largest element C std::lower_bound returns an iterator to the first element that is NOT LESS than value (>= value); std::upper_bound returns an iterator to the first element that is GREATER than value (> value) D They are identical
View answer & explanationFull Screen Mode →
47 How does 'std::stable_sort' differ from 'std::sort'? A std::stable_sort runs in O(n) time B std::stable_sort preserves the relative original order of equivalent elements (using Mergesort with O(n log n) time and O(n) additional memory); std::sort does not preserve relative order C std::stable_sort only works on arrays of integers D std::sort is thread-safe while stable_sort is not
View answer & explanationFull Screen Mode →
48 What sorting algorithm is typically used by 'std::sort' in modern C++ standard library implementations? A Introsort (Introductory Sort): starts with Quicksort, switches to Heapsort if recursion depth exceeds 2*log(n) to prevent O(n^2) worst case, and finishes with Insertion Sort on small partitions B Pure Quicksort C Mergesort D Bubblesort
View answer & explanationFull Screen Mode →
49 What is the average and worst-case time complexity of searching for an element in a std::unordered_map? A O(n) average case; O(n log n) worst case B O(log n) average and worst case C O(1) in all cases guaranteed D O(1) average case; O(n) worst case (when all keys hash to the same bucket causing hash collisions)
View answer & explanationFull Screen Mode →
50 What is the time complexity of searching, inserting, and deleting an element in a std::map or std::set? A Linear time: O(n) B Constant time: O(1) C Logarithmic time: O(log n) in both average and worst cases D Quadratic time: O(n^2)
View answer & explanationFull Screen Mode →