Last Updated: December 6, 2025
30 quizzes
Which preprocessor directive is MOST appropriate to prevent multiple inclusion of a header file in modern C++?
What is the main drawback of object-like macros used as constants?
Which using-directive or declaration is generally considered safest in headers?
Which header must you include to use std::is_integral and std::enable_if?
In SFINAE, what happens when template argument substitution fails in a candidate function template?
What kind of polymorphism does CRTP typically provide?
What is the primary motivation for using the Pimpl idiom?
Which key idea makes the copy-swap idiom exception-safe for copy assignment?
Which macro feature allows you to accept a variable number of arguments?
Which statement about inline namespaces is accurate?
Use conditional compilation to include <thread> only when MULTI_THREAD is defined
#ifdef MULTI_THREAD#include <>#endifClick an option to fill the blank:
Complete the macro to compute the maximum of two values safely with parentheses
#define MAX_SAFE(a, b) (((a) > (b)) ? (a) : ())Click an option to fill the blank:
Declare a nested namespace in C++17 for project::net
namespace project:: {}Click an option to fill the blank:
What is the output of this code using conditional compilation?
1#include <iostream>
2#define DEBUG 1
3int main() {
4#if DEBUG
5 std::cout << "Debug mode";
6#else
7 std::cout << "Release mode";
8#endif
9 return 0;
10}What is the output considering macro expansion?
1#include <iostream>
2#define SQUARE(x) ((x) * (x))
3int main() {
4 int a = 3;
5 std::cout << SQUARE(a + 1) << std::endl;
6 return 0;
7}What is the output regarding namespaces and scope resolution?
1#include <iostream>
2namespace A {
3 void f() { std::cout << "A"; }
4}
5namespace B {
6 void f() { std::cout << "B"; }
7}
8int main() {
9 using A::f;
10 f();
11 B::f();
12 return 0;
13}What is the output of this CRTP-based code?
1#include <iostream>
2
3template <typename Derived>
4class Base {
5public:
6 void run() {
7 static_cast<Derived*>(this)->impl();
8 }
9};
10
11class Worker : public Base<Worker> {
12public:
13 void impl() { std::cout << "Worker"; }
14};
15
16int main() {
17 Worker w;
18 w.run();
19 return 0;
20}What is the output of this copy-swap style assignment?
1#include <iostream>
2#include <utility>
3
4class Data {
5public:
6 Data(int v) : value(new int(v)) {}
7 Data(const Data& other) : value(new int(*other.value)) {}
8 ~Data() { delete value; }
9
10 void swap(Data& other) noexcept {
11 std::swap(value, other.value);
12 }
13
14 Data& operator=(Data other) {
15 swap(other);
16 return *this;
17 }
18
19 void print() const { std::cout << *value; }
20private:
21 int* value;
22};
23
24int main() {
25 Data a(1);
26 Data b(2);
27 b = a;
28 b.print();
29 return 0;
30}Find the bug related to the Pimpl idiom and memory management
Click on the line(s) that contain the bug.
#include <string> class Widget {public: Widget(); ~Widget(); void setName(const std::string& n);private: class Impl; Impl* pImpl;}; Widget::Widget() : pImpl(new Impl) {} Widget::~Widget() {} void Widget::setName(const std::string& n) { // use pImpl} Identify the bug in this SFINAE-based function template
Click on the line(s) that contain the bug.
#include <type_traits>#include <iostream> template <typename T>std::enable_if_t<std::is_integral<T>::value>printIfInt(T v) { std::cout << v << " is integral\n";} int main() { printIfInt(42); printIfInt(3.14);} Click the line that causes undefined behavior due to misuse of a macro
Click on the line to select.
#include <iostream>#define INCREMENT(x) ++x int main() { int n = 1; int m = INCREMENT(n) * INCREMENT(n); std::cout << n << " " << m << std::endl; return 0;}Click the line where the copy-swap idiom performs the swap operation
Click on the line to select.
#include <utility> class Buffer {public: Buffer(size_t n) : size(n), data(new int[n]) {} Buffer(const Buffer& other) : size(other.size), data(new int[other.size]) {} void swap(Buffer& other) noexcept { std::swap(size, other.size); std::swap(data, other.data); } Buffer& operator=(Buffer other) { swap(other); return *this; }private: size_t size; int* data;}; Complete the header guard using traditional preprocessor directives
#ifndef #define class Session {public: void run();};#endif // Click an option to fill blank 1:
Complete the type traits-based enable_if for integral types
#include <type_traits>template <typename T>std::enable_if_t<<T>::value, >process(T) { // implementation for integral types}Click an option to fill blank 1:
Complete this CRTP base class pattern
template <typename >class BaseLogger {public: void log(const std::string& msg) { static_cast<*>(this)->write(msg); }};Click an option to fill blank 1:
Complete the Pimpl idiom using std::unique_ptr for exception safety
#include <memory>class Engine {public: Engine(); ~Engine();private: class Impl; std::unique_ptr<Impl> ;};Engine::Engine() : (new Impl) {}Engine::~Engine() = default;Click an option to fill blank 1:
Match each type trait with what it checks
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each advanced C++ concept with its primary benefit
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Order the steps to implement a class using the Pimpl idiom
Drag and drop to reorder, or use the arrows.
Order the steps for using SFINAE with std::enable_if in a function template
Drag and drop to reorder, or use the arrows.