Last Updated: December 6, 2025
30 quizzes
Which naming convention best follows the described C++ coding standard for a boolean member?
Why should you mark read-only member functions as const?
According to the Rule of Zero, how should resource management usually be handled?
Which code most safely avoids a memory leak in modern C++?
Which is the MOST important first step before performance optimization?
Which modern C++ feature best supports RAII-based resource management?
In a multi-threaded C++ program, which is generally the safest way to protect shared data?
Which practice BEST helps when debugging a hard-to-reproduce bug?
Which declaration shows best const correctness for a read-only parameter?
A class manages a file handle. It defines a destructor but no copy/move operations. Which rule applies?
Declare a constant maximum buffer size following the described naming convention
const std::size_t = 4096;Click an option to fill the blank:
Make this member function const-correct
int getCount() { return count; }Click an option to fill the blank:
Use a smart pointer to express exclusive ownership of a dynamically allocated object
std::<Resource> res = std::make_unique<Resource>();Click an option to fill the blank:
What is the output of this code related to const pointers?
1#include <iostream>
2
3void foo() {
4 int value = 10;
5 const int* p1 = &value;
6 int* const p2 = &value;
7 *p2 = 20;
8 std::cout << *p1 << " " << *p2 << std::endl;
9}
10
11int main() {
12 foo();
13}What does this Rule-of-Three-inspired class print?
1#include <iostream>
2#include <cstring>
3
4class Buffer {
5public:
6 Buffer(const char* s) {
7 data = new char[std::strlen(s) + 1];
8 std::strcpy(data, s);
9 }
10 ~Buffer() { delete[] data; }
11 Buffer(const Buffer& other) {
12 data = new char[std::strlen(other.data) + 1];
13 std::strcpy(data, other.data);
14 }
15 void print() const { std::cout << data << std::endl; }
16private:
17 char* data{};
18};
19
20int main() {
21 Buffer a("Hello");
22 Buffer b = a;
23 b.print();
24}What is the output regarding smart pointer lifetime?
1#include <iostream>
2#include <memory>
3
4struct Tracer {
5 Tracer(const char* msg) : msg(msg) { std::cout << "ctor " << msg << '\n'; }
6 ~Tracer() { std::cout << "dtor " << msg << '\n'; }
7 const char* msg;
8};
9
10int main() {
11 {
12 std::unique_ptr<Tracer> p = std::make_unique<Tracer>("A");
13 std::cout << "inside" << '\n';
14 }
15 std::cout << "outside" << '\n';
16}What is the output for this range-based for loop example?
1#include <iostream>
2#include <vector>
3
4int main() {
5 std::vector<int> v{1, 2, 3};
6 for (auto x : v) {
7 x *= 2;
8 }
9 for (auto x : v) {
10 std::cout << x << " ";
11 }
12}What is the output when using std::lock_guard for thread-safe increments?
1#include <iostream>
2#include <thread>
3#include <mutex>
4
5int main() {
6 int counter = 0;
7 std::mutex m;
8
9 auto work = [&]() {
10 for (int i = 0; i < 1000; ++i) {
11 std::lock_guard<std::mutex> lock(m);
12 ++counter;
13 }
14 };
15
16 std::thread t1(work);
17 std::thread t2(work);
18 t1.join();
19 t2.join();
20
21 std::cout << counter << std::endl;
22}Find the bug related to memory management and Rule of Three/Five
Click on the line(s) that contain the bug.
#include <string> class ResourceHolder {public: ResourceHolder(const std::string& name) : name(name), data(new int[100]) {} ~ResourceHolder() { delete[] data; } private: std::string name; int* data;}; ResourceHolder makeCopy(ResourceHolder r) { return r;}Find the bug that can cause undefined behavior in this debugging example
Click on the line(s) that contain the bug.
#include <iostream> int divide(int a, int b) { int result = a / b; return result;} int main() { int x = 10; int y = 0; std::cout << divide(x, y) << std::endl;}Click the line that causes a memory leak when an early return happens
Click on the line to select.
void process(bool error) { int* data = new int[100]; // use data if (error) return; delete[] data;}Click the line that violates const correctness best practices
Click on the line to select.
#include <string> class User {public: User(const std::string& name) : name(name) {} const std::string& getName() { return name; } private: std::string name;};Complete the RAII-style class that manages a file using modern C++ and const correctness
#include <fstream>class FileGuard {public: FileGuard(const std::string& path) : file(path) {} bool () const { return file.is_open(); } void write(const std::string& text) private: std::ofstream file;};Click an option to fill blank 1:
Fix const correctness in this accessor following the guidelines
class Config {public: Config(int v) : value(v) {} int () { return value; }private: int value;};Click an option to fill blank 1:
Use modern C++ to safely share ownership of a dynamically created object
#include <memory>struct Data { };int main() { auto p1 = std::<Data>(new Data{}); std::<Data> p2 = p1;}Click an option to fill blank 1:
Complete this performance-conscious loop using references to avoid copies
#include <vector>int sum(const std::vector<int>& v) { int s = 0; for ( x : ) { s += x; } return s;}Click an option to fill blank 1:
Match each rule with its main recommendation
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each modern C++ guideline with its benefit
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Order the typical debugging steps for a tricky C++ bug
Drag and drop to reorder, or use the arrows.
Order the steps to implement a safe, high-performance C++ feature
Drag and drop to reorder, or use the arrows.