Last Updated: December 6, 2025
30 quizzes
When is using 'auto' most appropriate in modern C++?
Which expression is the safest modern C++ way to represent a null pointer?
Which constructor enables brace initialization with a variable number of elements?
What is a key benefit of uniform (brace) initialization?
For which type is a move constructor most beneficial?
What does a parameter of type T&& in a function template usually represent?
Which statement about constexpr functions is correct in C++14 and later?
What happens if you call value() on an empty std::optional<int>?
Which utility is typically used to visit the active alternative of a std::variant?
Which statement about std::string_view is true?
Use auto with an iterator returned from std::vector<int>::begin()
std::vector<int> v{1,2,3}; auto = v.begin();Click an option to fill the blank:
Use nullptr to initialize a raw pointer member
int* current = ;Click an option to fill the blank:
Use std::filesystem::path to join a directory and filename
std::filesystem::path full = dir / ;Click an option to fill the blank:
What is the output of this code using auto and initializer lists?
1#include <iostream>
2#include <vector>
3int main() {
4 std::vector<int> v{1, 2, 3};
5 auto sum = 0;
6 for (auto x : v) sum += x;
7 std::cout << sum << "\n";
8 return 0;
9}What is the output related to move semantics?
1#include <iostream>
2#include <string>
3
4struct S {
5 std::string name;
6 S(std::string n) : name(std::move(n)) {}
7};
8
9int main() {
10 std::string s = "hello";
11 S a{s};
12 S b{std::move(s)};
13 std::cout << a.name << " " << b.name << " " << s << "\n";
14}What is the output using constexpr and compile-time calculation?
1#include <iostream>
2constexpr int mul(int a, int b) { return a * b; }
3int main() {
4 constexpr int v = mul(3, 4);
5 int x = 2;
6 std::cout << v << " " << mul(x, 5) << "\n";
7}What is the output when using std::optional?
1#include <iostream>
2#include <optional>
3
4std::optional<int> find_positive(int x) {
5 if (x > 0) return x;
6 return std::nullopt;
7}
8
9int main() {
10 auto a = find_positive(5);
11 auto b = find_positive(-1);
12 std::cout << a.has_value() << " " << b.has_value() << "\n";
13}What is the output when using structured bindings with std::pair?
1#include <iostream>
2#include <utility>
3
4std::pair<int, int> f() {
5 return {1, 2};
6}
7
8int main() {
9 auto [x, y] = f();
10 x += 3;
11 std::cout << x << " " << y << "\n";
12}Find the bug in this code using std::string_view
Click on the line(s) that contain the bug.
#include <string>#include <string_view> std::string_view make_view() { std::string s = "temp"; return s;} int main() { auto v = make_view(); return v.size();}Find the bug in this code using std::filesystem
Click on the line(s) that contain the bug.
#include <filesystem>#include <iostream> int main() { std::filesystem::path p{"/tmp"}; if (std::filesystem::is_regular_file(p)) { std::cout << "dir\n"; } else if (std::filesystem::is_directory(p)) { std::cout << "file\n"; }}Click the line where perfect forwarding should be used instead of passing arg directly
Click on the line to select.
#include <utility> void log(int&) {}void log(int&&) {} template <typename T>void wrapper(T&& arg) { log(arg);} int main() { int x = 1; wrapper(x); wrapper(2);}Click the line that may throw std::bad_variant_access
Click on the line to select.
#include <variant>#include <string> int main() { std::variant<int, std::string> v = std::string{"hi"}; int i = std::get<int>(v); return i;}Complete the constructor to support std::initializer_list for a Matrix
#include <vector>class Matrix { std::vector<int> data;public: Matrix(std::initializer_list<int> ) : data() {}};Click an option to fill blank 1:
Fill in types for structured bindings from std::pair
#include <utility>int main() { std::pair<int, double> p{1, 2.5}; auto [, ] = p;}Click an option to fill blank 1:
Use std::filesystem to check if a path exists and is a directory
#include <filesystem>bool is_dir(const std::filesystem::path& p) { return std::filesystem::(p) && std::filesystem::(p);}Click an option to fill blank 1:
Complete the function that returns std::optional<std::string_view>
#include <optional>#include <string_view>std::optional<std::string_view> first_word(std::string_view text) { auto pos = text.find(' '); if (pos == std::string_view::npos) return ; return text.substr(0, pos);}Click an option to fill blank 1:
Match the modern C++ feature with its primary purpose
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match the move-related concept with its description
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Order the steps to safely read a text file using std::filesystem and std::ifstream
Drag and drop to reorder, or use the arrows.
Order the steps to implement perfect forwarding in a wrapper function
Drag and drop to reorder, or use the arrows.