C++163 questions in the bank

C++ Quiz: Test Your C++ Knowledge

Pick how many questions you want, choose a difficulty and go. You'll see why each answer is right or wrong, then you can retry to beat your score.

Questions
Difficulty
Topic
Mode
  1. Where does every C++ program start running?

    • At #include
    • At the first cout
    • In a class called Main
    • In the main function
  2. What file extension do C++ source files usually use?

    • .c++
    • .cxx only
    • .cpp
    • .h
  3. What does return 0; at the end of main mean?

    • The program finished successfully
    • Print 0
    • Restart the program
    • The program had an error
  4. What does the compiler do?

    • Runs your code line by line
    • Checks your code and turns it into a program the computer can run
    • Formats your code
    • Downloads libraries
  5. Which header do you include to use cout?

    • <stdio>
    • <output>
    • <iostream>
    • <string>
  6. Which type holds true or false?

    • int
    • char
    • bool
    • string
  7. What does const do?

    • Makes a variable faster
    • Prevents the value from being changed after it's set
    • Makes the variable global
    • Converts the value to a string
  8. What does auto x = 2.5; create?

    • A double
    • An int
    • A string
    • A variable with no type
  9. Why might getline return an empty string right after cin >> age;?

    • getline only works at the start of a program
    • It reads the Enter key left behind by cin >>
    • age must be a string
    • cin closes after one use
  10. How do you read a whole line, including spaces, into a string?

    • getline(cin, line);
    • cin >> line;
    • cin.read(line);
    • readline(line);
  11. Which header provides sqrt and pow?

    • <cmath>
    • <iostream>
    • <string>
    • <random>
  12. What does static_cast<int>(8.9) give?

    • 9
    • 8.9
    • An error
    • 8
  13. What does ceil(2.1) return?

    • 2
    • 2.1
    • 2.5
    • 3
  14. What's the modern C++ way to roll a fair six-sided dice?

    • rand() % 6
    • random(6)
    • uniform_int_distribution<int>(1, 6) with an mt19937 generator
    • dice(6)
  15. Why does cout << 3.0; print 3?

    • By default cout doesn't show trailing zeros
    • 3.0 is stored as an int
    • cout rounds every number
    • It's a compiler bug
  16. Which header do you include for std::string?

    • <iostream>
    • <text>
    • <string>
    • <cstring>
  17. How does s.at(i) differ from s[i]?

    • There's no difference
    • at() checks the position and throws an exception if it's invalid
    • at() returns a copy, [] returns a reference
    • [] only works on const strings
  18. Are C++ std::string objects mutable?

    • No, every change creates a new string
    • Only if declared mutable
    • Only with pointers
    • Yes, functions like insert and erase change the string itself
  19. Which function turns the number 15 into the text "15"?

    • stoi(15)
    • string(15)
    • to_string(15)
    • str(15)
  20. Why is "Hi" + " there" an error?

    • Strings can't contain spaces
    • Both are character array literals, and + isn't defined for two of them
    • + only joins numbers
    • You must use append()
  21. What does ! do?

    • Reverses a boolean value
    • Ends a statement
    • Compares two values
    • Marks a comment
  22. What happens if a switch case has no break?

    • The program crashes
    • The compiler reports an error
    • Execution continues into the next case
    • The switch restarts
  23. Which value does (10 > 3) ? "yes" : "no" produce?

    • "no"
    • true
    • 1
    • "yes"
  24. Can switch be used directly with a std::string?

    • Yes, always
    • No, it only works with whole-number types like int and char
    • Only with short strings
    • Only with const strings
  25. What's wrong with if (x = 5)?

    • It assigns 5 to x instead of comparing, so the condition is always true
    • Nothing
    • It doesn't compile
    • It compares the address of x
  26. What does i++ do?

    • Doubles i
    • Adds 1 to i
    • Prints i
    • Sets i to 0
  27. In nested loops, what does break exit?

    • Only the innermost loop it's in
    • Every loop
    • The whole program
    • Only the outer loop
  28. When is a while loop's condition checked?

    • After each pass
    • Only once
    • Before each pass
    • Only when it changes
  29. What is the value of n after int n = 0; while (n < 20) n += 7;?

    • 14
    • 20
    • 28
    • 21
  30. Which loop always runs its body at least once?

    • do-while
    • for
    • while
    • range-based for
  31. What return type does a function that returns nothing use?

    • null
    • empty
    • int
    • void
  32. What is a function prototype?

    • A declaration of the function's signature, ending in a semicolon
    • An unfinished function
    • A function with no parameters
    • A function inside main
  33. What does & after a parameter's type do?

    • Makes it optional
    • Makes it constant
    • Passes the argument by reference
    • Doubles its value
  34. Which pair of functions is a valid overload?

    • int f(int a) and int f(double a)
    • int f(int a) and double f(int a)
    • int f(int a) and int f(int b)
    • void f() and int f()
  35. What is a function prototype?

    • The first call to a function
    • A declaration of the function's name, parameters and return type before its body
    • A function with no body ever
    • A template
  36. What header do you need for std::vector?

    • <array>
    • <vector>
    • <list>
    • <iostream>
  37. What's the main difference between an array and a vector?

    • Arrays can hold strings; vectors can't
    • Vectors start counting at 1
    • A vector can change size; a classic array can't
    • Arrays are always faster to write
  38. Which loop visits every value in vector v without using an index?

    • for (int x : v)
    • for (v : int x)
    • foreach (int x in v)
    • for (x in v)
  39. Why pass a large vector as const vector<int>&?

    • It makes the vector constant everywhere
    • It's required for all vectors
    • It avoids copying the vector and prevents the function from changing it
    • It sorts the vector
  40. Why pass a vector to a function as const vector<int>&?

    • To make it bigger
    • To avoid copying it while promising not to change it
    • Vectors can't be passed by value
    • To sort it
  41. What is a recursive function?

    • A function that calls itself
    • A function with a loop
    • A function with no return value
    • A function inside a class
  42. What is the base case?

    • The first line of main
    • The largest input
    • The default parameter
    • The simplest input, answered directly without another recursive call
  43. How many calls does binary search need for about a million sorted items?

    • About a million
    • About 1,000
    • About 20
    • Exactly 2
  44. What does each recursive call get on the call stack?

    • Nothing
    • Its own frame with its own parameters and local variables
    • A shared copy of every variable
    • A new thread
  45. When is a loop usually better than recursion?

    • Simple repetition that could go millions of levels deep
    • Walking a folder tree
    • Binary search
    • Solving a maze
  46. Which header provides setw and setprecision?

    • <iostream>
    • <iomanip>
    • <string>
    • <sstream>
  47. What does boolalpha change?

    • Booleans print as true and false instead of 1 and 0
    • Letters to capitals
    • Sorting order
    • Number bases
  48. How do you get the text out of an ostringstream called out?

    • out.text()
    • string(out)
    • out.str()
    • out.toString()
  49. What does stoi("15") return?

    • "15"
    • 1.5
    • An error
    • The int 15
  50. Why might formatting into an ostringstream be safer than changing cout's settings?

    • It's faster
    • cout can't format numbers
    • cout's sticky settings would otherwise affect every later output in the program
    • ostringstream adds colours
  51. How do you access a struct member?

    • With ->
    • With ::
    • With a dot, like p.name
    • With []
  52. Why use enum class instead of plain enum?

    • Its names are scoped and it won't silently convert to int
    • It's faster
    • It can hold strings
    • It allows more values
  53. What is a good use for a struct?

    • Repeating code
    • Printing output
    • Reading files
    • Grouping related values, such as the name, price and stock of a product
  54. Why loop with Product& instead of Product?

    • It's required for structs
    • To change the items in the vector instead of copies
    • To sort the vector
    • To make the loop shorter
  55. How can a function return three values at once?

    • It can't
    • Use three return statements
    • Return an enum
    • Return a struct containing the three values
  56. What does a pointer store?

    • A copy of a value
    • A function
    • A memory address
    • A type name
  57. What does *p mean in an expression when p is a pointer?

    • Multiply p
    • The address of p
    • A new pointer
    • The value at the address stored in p
  58. What should a pointer hold when it points to nothing?

    • nullptr
    • 0x0000 as a string
    • -1
    • An empty string
  59. What is wrong with returning &n where n is a local variable?

    • Nothing
    • You can only return references
    • n is destroyed when the function ends, so the pointer is left dangling
    • It returns the wrong type
  60. What is (*p).name equivalent to?

    • p.name
    • p->name
    • &p->name
    • *p->name
  61. What is the default access for class members in C++?

    • private
    • public
    • protected
    • There is no default
  62. What is encapsulation?

    • Putting classes in separate files
    • Creating many objects
    • Inheriting from a class
    • Keeping data private and allowing changes only through member functions
  63. How is a destructor written?

    • destroy Name()
    • Name::delete()
    • ~Name()
    • void Name()
  64. What does double Account::getBalance() const mean outside a class?

    • A new class
    • The definition of Account's getBalance member function
    • A global function called Account
    • A call to getBalance
  65. Why prefer deposit(amount) over setBalance(x)?

    • It describes a real action and can enforce the class's rules
    • It's shorter
    • Setters aren't allowed in C++
    • It's faster
  66. In what order does std::map store its keys?

    • Insertion order
    • Random order
    • Sorted order
    • Reverse insertion order
  67. What does a std::set guarantee?

    • Values in insertion order
    • Each value appears only once
    • Constant size
    • Values can be changed in place
  68. What are structured bindings in for (const auto& [k, v] : m)?

    • A way to sort maps
    • A kind of pointer
    • A map method
    • A way to unpack each pair into two named variables
  69. What is [](int x) { return x > 10; }?

    • A lambda: a small unnamed function
    • An array
    • A map literal
    • A template
  70. Why can m[key] be risky when only reading?

    • It throws an exception
    • It inserts the key with a default value if it isn't already there
    • It deletes the key
    • It returns a copy of the map
  71. Which header contains sort and find?

    • <algorithm>
    • <vector>
    • <numeric>
    • <iterator>
  72. What does find return when the value isn't present?

    • -1
    • nullptr
    • The end() iterator
    • An exception
  73. What is a predicate?

    • A loop
    • A sorted range
    • A type of iterator
    • A function that returns true or false for an item
  74. In a sort comparison lambda (a, b), what should it return?

    • true if a should come before b
    • a minus b
    • The larger item
    • 0, 1 or -1
  75. Which C++20 function removes matching items from a vector in one call?

    • remove_all
    • erase_if
    • filter
    • delete_if
  76. Which keyword signals an error?

    • catch
    • throw
    • try
    • error
  77. What does e.what() return?

    • The line number
    • The exception's type
    • The exception's message
    • true or false
  78. What does stoi("hello") throw?

    • invalid_argument
    • out_of_range
    • runtime_error
    • Nothing, it returns 0
  79. What does catch (...) catch?

    • Only standard exceptions
    • Nothing
    • Only runtime_error
    • Any exception of any type
  80. When is returning a value better than throwing?

    • Always
    • When the outcome is expected and common, such as "not found"
    • When the error is serious
    • Never
  81. Which header provides ifstream and ofstream?

    • <iostream>
    • <file>
    • <stdio>
    • <fstream>
  82. What happens when you open an existing file with a plain ofstream?

    • Its contents are erased first
    • It's appended to
    • An error occurs
    • It opens read-only
  83. How do you check that a file opened successfully?

    • if (in == true)
    • if (!in) or if (!in.is_open()) handles the failure
    • in.check()
    • It always opens
  84. What is a stringstream useful for?

    • Downloading files
    • Encrypting text
    • Sorting strings
    • Reading from or writing to a string as if it were a stream, e.g. splitting a line
  85. When is a file opened with an ofstream closed?

    • Only when the program ends
    • After every write
    • When close() is called or the stream object goes out of scope
    • Never automatically
  86. How does a derived class call its base class's constructor?

    • base(args) inside the body
    • super(args)
    • It can't
    • In the initializer list: Derived(int x) : Base(x) {}
  87. What does override do?

    • Makes a function virtual
    • Hides the base function from all code
    • Asks the compiler to check that the function overrides a virtual base function
    • Makes the function faster
  88. Who can access a protected member?

    • The class itself and its derived classes
    • Any code
    • Only the class itself
    • Only main
  89. Why does a polymorphic base class need a virtual destructor?

    • To speed up deletion
    • Destructors must always be virtual
    • To allow copying
    • So deleting a derived object through a base pointer also runs the derived destructor
  90. Through which kinds of variables does polymorphism work?

    • Only by-value base objects
    • Base-class references and pointers
    • Only global variables
    • Only const objects
  91. What is operator overloading?

    • Using too many operators
    • Creating new symbols
    • Defining how operators like + and == work for your own types
    • Changing how + works for int
  92. What does C++20's auto operator<=>(const T&) const = default; give you?

    • All the comparison operators, comparing members in order
    • Only <
    • Printing support
    • Addition
  93. Why does the non-const operator[] return a reference?

    • To save memory
    • So code like w[0] = 7.5 can change the stored value
    • References are faster to print
    • It must return void
  94. Why mark operator+ as const?

    • It's required by the compiler
    • It makes the result const
    • It makes it a non-member function
    • It promises not to change the object, and lets it work on const objects
  95. Which is a poor use of operator overloading?

    • + to add two Money values
    • == to compare two Points
    • + to remove an item from a list
    • << to print a Vec2
  96. What is a declaration?

    • The body of a function
    • A statement that something exists, with its name and type
    • A comment
    • A compiled file
  97. What does the one definition rule say?

    • Each file may have one function
    • Each class may have one constructor
    • Each project may have one header
    • Each function or variable may be defined only once in the whole program
  98. What does the linker do?

    • Checks spelling
    • Downloads libraries
    • Joins compiled object files into one program
    • Runs the program
  99. How do you call area inside namespace geo from main?

    • area()
    • geo.area()
    • namespace.area()
    • geo::area()
  100. What's the main job of CMake?

    • Compiling C++ itself
    • Formatting code
    • Describing the project once and generating build commands for any compiler and system
    • Running unit tests only
  101. Where do objects created with new live?

    • On the heap
    • On the stack
    • In a file
    • In the CPU cache only
  102. What is a memory leak?

    • Reading a file twice
    • A pointer to a stack variable
    • Heap memory that's never freed after it's no longer needed
    • A stack overflow
  103. What does RAII mean in practice?

    • Always use raw pointers
    • A resource is acquired in a constructor and released in the destructor
    • Allocate everything at program start
    • Never use classes
  104. Which smart pointer should you choose by default?

    • shared_ptr
    • weak_ptr
    • unique_ptr
    • auto_ptr
  105. When is an object managed by shared_ptr deleted?

    • When the first shared_ptr is destroyed
    • At the end of main only
    • Never
    • When the last shared_ptr owning it is destroyed or reset
  106. What's the main benefit of moving over copying?

    • Moving changes the values
    • Moving is required for ints
    • Moving sorts the data
    • Moving transfers existing memory instead of duplicating every element
  107. Does std::move itself move anything?

    • Yes, it copies then deletes
    • Yes, but only for strings
    • No, it only marks a value as allowed to be moved from
    • Only when used with new
  108. What does the rule of zero recommend?

    • Use well-behaved members like string, vector and unique_ptr, and write none of the copy or move functions
    • Always write five special functions
    • Never use classes
    • Avoid constructors
  109. What can you safely do with a moved-from object?

    • Read its old values
    • Nothing at all
    • Move from it again to get the data back
    • Destroy it or assign it a new value
  110. Why not write return std::move(localVariable);?

    • It doesn't compile
    • The compiler already moves or constructs the return value in place, and std::move can prevent that
    • It copies twice
    • Return values can't be moved
  111. What problem do templates solve?

    • Slow programs
    • Writing the same function or class again for different types
    • Memory leaks
    • Reading files
  112. Which of these is a class template?

    • std::vector
    • int
    • cout
    • main
  113. How do you explicitly choose the type for a function template?

    • f(int, 3, 4)
    • f(3, 4)<int>
    • int f(3, 4)
    • f<int>(3, 4)
  114. What do C++20 concepts do?

    • Replace classes
    • Run templates at run time
    • Describe requirements for template types and give clearer errors
    • Remove the need for typename
  115. Is there a run-time cost to using a function template compared with hand-written versions?

    • Yes, templates are always slower
    • No, each instantiation is ordinary compiled code for its type
    • Only for strings
    • Only in debug builds
  116. Which header provides std::optional?

    • <optional>
    • <vector>
    • <utility>
    • <variant>
  117. What happens if you call .value() on an empty optional?

    • It returns 0
    • It returns nullptr
    • It throws bad_optional_access
    • Nothing
  118. What does std::visit do?

    • Prints a variant
    • Calls a function with the value the variant currently holds
    • Converts a variant to a string
    • Lists the variant's types
  119. What does auto [a, b] = p; do for a pair p?

    • Creates an array
    • Unpacks p's two members into variables a and b
    • Compares a and b
    • Swaps the pair
  120. How is a variant safer than a C-style union?

    • It always knows which type it holds and stops you reading the wrong one
    • It's smaller
    • It can hold several values at once
    • It doesn't need a header
  121. Which header provides std::thread?

    • <process>
    • <async>
    • <mutex>
    • <thread>
  122. What does f.get() do on a future?

    • Starts the task
    • Cancels the task
    • Waits for the result if needed, then returns it
    • Returns immediately with 0
  123. When is std::atomic a good choice?

    • For protecting a whole vector
    • For simple shared counters and flags
    • For reading files
    • Never
  124. Why use ref() when passing a variable to std::thread?

    • It makes the thread faster
    • It locks the variable
    • It's required for every argument
    • std::thread copies its arguments, so ref is needed to pass a real reference
  125. What's the safest overall design for multithreaded work?

    • Share everything and add locks later
    • Use as many threads as possible
    • Give each thread its own data, then combine results after joining
    • Avoid join
  126. What does an inner variable with the same name do?

    • Hide the outer declaration for applicable name lookup.
    • Destroy the outer object immediately.
    • Give the outer object internal linkage.
    • Extend every local object's lifetime.
  127. Which placement fits an implementation-only free helper?

    • A broad using directive in every public header.
    • An unnamed namespace in the implementation source file.
    • A public declaration in the API merely to hide it later.
    • An automatic local variable in an unrelated function.
  128. What does const int* p restrict?

    • Reassigning p to another integer.
    • Modifying the integer through p.
    • Modifying the same integer through every other alias.
    • Reading the integer's value.
  129. A const collection's at method returns a reference. Which return type preserves read-only access?

    • T&&, to permit moving from every const collection.
    • T&
    • const T&
    • T&, because a const member always makes its returned reference const.
  130. What does static_cast by itself establish for a narrowing numeric conversion?

    • That every source value fits.
    • That fractional input is rounded to nearest.
    • That the conversion is explicitly requested under the language rules.
    • That arithmetic before the cast cannot overflow.
  131. Which signed-overflow strategy is sound?

    • Replace every signed type with unsigned without reviewing the requirement.
    • Add first and inspect whether the result became negative.
    • Assume debug and release builds wrap identically.
    • Prove the operation fits before performing it.
  132. Which object owns elements in the main example?

    • The sum function's span parameter.
    • The function retains ownership by accepting the span by value.
    • The subspan returned temporarily.
    • The std::array.
  133. A span points into a vector that reallocates. What should be assumed?

    • The old view may be invalid and must not be used without reestablishing validity.
    • Span automatically follows the new allocation.
    • The vector cannot reallocate while a span exists.
    • Const element type transfers ownership.
  134. What does string_view own?

    • No character storage; it borrows a sequence.
    • The original string and its allocator.
    • A copied null terminator for every substring.
    • A shared reference count to every source.
  135. A substring view is passed to a C function that receives only data(). What is the concern?

    • data() necessarily points to a new, terminated substring allocation.
    • The view's end may not be null-terminated under the function's contract.
    • The original string's terminator must occur at the view's end.
    • remove_suffix writes a new terminator at the shortened boundary.
  136. What should an erase-while-iterating loop do after erasing the current element?

    • Increment the erased iterator.
    • Assign the iterator returned by erase.
    • Dereference the old end iterator.
    • Assume the original range is unchanged.
  137. A vector reallocates while growing. What happens to old element pointers?

    • Only pointers to the final element are affected.
    • They automatically track the new allocation.
    • They are invalidated and must not be used as though still valid.
    • Calling reserve after reallocation repairs every previously saved pointer.
  138. Which statement about deque is correct?

    • Its elements are guaranteed to form one contiguous array.
    • It permits dereferencing front on an empty container.
    • It supports efficient endpoint operations and random access.
    • Every iterator remains valid after every mutation.
  139. Why can a list still be slow for insertion by a searched value?

    • Its iterators are random-access pointers.
    • List insertion always copies every other node.
    • Locating a value is constant time because insertion at a known node is constant time.
    • Finding the position can require linear traversal.
  140. Which value is next after pushing 3, 7 and 4 into a stack?

    • 3, because it arrived first.
    • 7, because it is largest.
    • No value until the stack is sorted.
    • 4, because it was pushed last.
  141. What must a priority comparator satisfy?

    • A strict weak ordering compatible with the intended priority policy.
    • It must return true for equal values.
    • It must compare only memory addresses.
    • It must preserve FIFO automatically without a tie key.
  142. Which equality/hash rule is required?

    • Equivalent keys must produce equal hashes.
    • Every unequal key must have a unique hash.
    • Hashes must be sorted in iteration order.
    • Hash values must remain permanent external identifiers.
  143. What can operator[] do when the key is absent?

    • Always return a read-only missing marker.
    • Insert a default mapped value.
    • Return a missing marker without changing the map.
    • Prevent future rehashing.
  144. Which clock is the ordinary choice for elapsed-operation deadlines?

    • System_clock solely because it prints dates.
    • Steady_clock.
    • Any clock named high_resolution without checking its contract.
    • System_clock, assuming wall-clock adjustments cannot affect elapsed comparisons.
  145. What does integral duration_cast from 1500 milliseconds to seconds produce?

    • 2 because it always rounds upward.
    • 1.5 as an integral count.
    • 1 by truncating the fractional part.
    • 1500 because units are ignored.
  146. What role does a distribution play?

    • It owns every application's global seed.
    • It automatically encrypts generated values.
    • It maps engine output into a chosen probability model or range.
    • It makes every short sample contain every possible outcome.
  147. Why can exact dice output differ across standard libraries with the same mt19937 seed?

    • A conforming distribution may emit values outside its declared closed interval.
    • The engine sequence is unspecified even for its documented deterministic seed constructor.
    • Using the same seed forces every distribution implementation to use the same mapping algorithm.
    • Distribution mapping algorithms can differ while satisfying their contract.
  148. Which statement about a friend function is correct?

    • It automatically has a this pointer.
    • It makes all private fields public to everyone.
    • It can be invoked only through an object of the granting class.
    • It remains a nonmember with granted private access.
  149. Warehouse grants Auditor friendship, and Auditor grants Helper friendship. What follows?

    • Helper does not automatically gain Warehouse private access.
    • Warehouse automatically gains Auditor's private access in return.
    • Warehouse can automatically access every Auditor field.
    • Friendship propagates through every dependency.
  150. What does ordinary nonvirtual diamond inheritance commonly create?

    • Separate common-base subobjects along the relevant paths.
    • One automatically shared common base.
    • A runtime error before construction in every case.
    • No base state at all.
  151. Which class initializes a shared virtual base in a final object?

    • Whichever intermediate constructor appears last in source.
    • The most-derived class.
    • The first caller that uses a base reference.
    • Every intermediate class independently creates a shared copy.
  152. What does the strong exception guarantee promise?

    • Every operation must be faster than copying.
    • Failure leaves the prior documented state unchanged.
    • Every function becomes noexcept automatically.
    • External services undo their effects automatically.
  153. Why reset Buffer's moved-from size?

    • Because declaring the move noexcept also resets scalar metadata.
    • Because std::move resets all integers automatically.
    • To keep its size and storage ownership invariant coherent.
    • To prevent the destination from owning storage.
  154. What is deduced for T in describe(T&&) when called with an int lvalue?

    • Plain int, followed by an automatic move from the caller's lvalue.
    • Always plain int regardless of argument category.
    • An applicable lvalue-reference type.
    • int&&, because the parameter spelling contains two ampersands.
  155. Which template facility permits partial specialization?

    • A function-template overload, treated as a partial specialization of another function.
    • An ordinary non-template function.
    • A function template through any arbitrary partial argument list.
    • A class template under its specialization rules.
  156. What does a requires expression primarily check?

    • That a runtime operation has already succeeded.
    • That all values fit in the destination integer type.
    • That every accepted method is thread-safe.
    • Whether specified expressions and types satisfy compile-time requirements.
  157. Why does CountType exclude bool?

    • Boolean satisfies relevant integral classifications but is not an intended quantity representation.
    • Boolean can never satisfy a standard integral concept.
    • Unsigned classification alone proves the type represents the intended quantity domain.
    • A requires clause automatically rejects Boolean arguments without an explicit restriction.
  158. When does a typical filter-transform view compute its selected values?

    • As the view is traversed under its contract.
    • Every value is copied during pipeline construction.
    • After automatically storing every transformed value in an owning result container.
    • Only during construction, even if source elements later change.
  159. A report must survive destruction of its source products. Which result fits?

    • A returned view into a local vector.
    • An owning vector of copied or moved report values.
    • A lambda retaining a reference to a destroyed threshold.
    • An iterator into the cleared source.
  160. What should a regression check preserve?

    • The exact sequence of implementation statements.
    • The input condition and promised observable behavior.
    • Every memory address from one run.
    • A passing result after arbitrary retries.
  161. Why is checking signed overflow only after addition unsound?

    • Examining a wrapped result makes the preceding signed overflow defined.
    • Every overflow necessarily throws std::overflow_error automatically.
    • The undefined operation has already occurred.
    • The same post-addition check is safe merely because the debug build passed.
  162. Which command relationship declares that pricing_app uses pricing?

    • A global include_directories call alone.
    • Listing pricing.cpp in the library without linking the library target to the app.
    • target_link_libraries(pricing_app PRIVATE pricing).
    • Adding the library include directory while omitting its link dependency.
  163. For ordinary single-configuration Ninja, where is Debug selected?

    • Through CXX_EXTENSIONS OFF, which selects optimization and debug-symbol settings.
    • At build time solely with --config Debug after configuring a Release directory.
    • Automatically from every --config option regardless of generator.
    • At configuration through CMAKE_BUILD_TYPE or an equivalent preset setting.
RelaxedNo clock. Read the explanation after each answer.
Timed30 seconds per question. Great for revision.
Exam modeNo feedback until the end, then a full review.

About the C++ quiz

This C++ quiz covers every lesson in the course, from cout and cin to classes, move semantics, templates and threads. Many questions show a few lines of C++ and ask what they print, which trains you to follow code exactly the way the compiler does. Others check the concepts that make C++ different from other languages: references and pointers, const, object lifetimes, and why a base class needs a virtual destructor.

If you've only finished the beginner stage, choose Easy and a topic such as Strings or Loops. After the intermediate lessons, try Mixed with 10 questions, because functions, vectors, structs and pointers are used together in every real program. Save Exam mode for the end of the course, when you want an honest check without seeing answers along the way.

C++ mistakes often come from a small set of traps: integer division dropping decimals, a missing semicolon after a class or struct, forgetting break in a switch, reading past the end of an array, changing a copy instead of a reference, and using a pointer after the object it points to has gone. When a question catches you out, read the explanation and revisit the linked lesson's common mistakes. Spotting these traps in a quiz saves hours of debugging later.

The question bank holds 163 questions drawn from 44 C++ lessons: 45 easy, 93 medium and 25 hard. Every time you start, the quiz picks a fresh random selection that matches your settings, so retaking it is a good way to practise. After each answer, or at the end in exam mode, you'll see why the right answer is right, and every question you miss links back to the lesson that teaches it.

What the C++ quiz covers