Practice / cpp

C++ practice

Every C++ exercise, built from a topic you can open beside it.

92 exercises runs offline
cpp Quiz new After array-to-pointer conversion, what is the type of int grid[2][3] in an ordinary expr… Built-in C++23 arrays, including bounds, initialization, pointer conversion, multidimensional layout, lifetime, and safer standard-library alternatives. intermediate 1 min · from C-style arrays cpp Quiz new What contract does void read(const int values[8]) enforce in C++23? Built-in C++23 arrays, including bounds, initialization, pointer conversion, multidimensional layout, lifetime, and safer standard-library alternatives. beginner 1 min · from C-style arrays cpp Predict the output new What does this program print? Built-in C++23 arrays, including bounds, initialization, pointer conversion, multidimensional layout, lifetime, and safer standard-library alternatives. beginner 2 min · from C-style arrays cpp Review AI code new Review generated reading average Built-in C++23 arrays, including bounds, initialization, pointer conversion, multidimensional layout, lifetime, and safer standard-library alternatives. advanced 6 min · from C-style arrays cpp Spot the bug new Spot the bug in the four-element total Built-in C++23 arrays, including bounds, initialization, pointer conversion, multidimensional layout, lifetime, and safer standard-library alternatives. beginner 4 min · from C-style arrays cpp Quiz new Which statement about sizeof(char) is portable C? Start with translation units, types, and expressions, then learn C23 control flow, functions, error boundaries, conversions, and undefined behavior. beginner 2 min · from C fundamentals cpp Predict the output new What does this program print? Start with translation units, types, and expressions, then learn C23 control flow, functions, error boundaries, conversions, and undefined behavior. beginner 2 min · from C fundamentals cpp Review AI code new Review generated reading average Start with translation units, types, and expressions, then learn C23 control flow, functions, error boundaries, conversions, and undefined behavior. advanced 10 min · from C fundamentals cpp Spot the bug new Spot the bug in the balance comparison Start with translation units, types, and expressions, then learn C23 control flow, functions, error boundaries, conversions, and undefined behavior. intermediate 4 min · from C fundamentals cpp Quiz new What may portable C conclude about int next = index++ + index;? Start with translation units, types, and expressions, then learn C23 control flow, functions, error boundaries, conversions, and undefined behavior. intermediate 3 min · from C fundamentals cpp Quiz new What does fread(buffer, sizeof(uint32_t), 8, stream) return? Open, read, write, and seek files reliably with C23 stdio streams while handling EOF, short counts, buffering, and close errors. beginner 2 min · from C file I/O cpp Predict the output new What does this program print? Open, read, write, and seek files reliably with C23 stdio streams while handling EOF, short counts, buffering, and close errors. beginner 3 min · from C file I/O cpp Review AI code new Review generated file copy Open, read, write, and seek files reliably with C23 stdio streams while handling EOF, short counts, buffering, and close errors. advanced 12 min · from C file I/O cpp Spot the bug new Spot the bug in the byte-copy loop Open, read, write, and seek files reliably with C23 stdio streams while handling EOF, short counts, buffering, and close errors. intermediate 4 min · from C file I/O cpp Quiz new On an r+b update stream, what must normally separate a successful read from a following w… Open, read, write, and seek files reliably with C23 stdio streams while handling EOF, short counts, buffering, and close errors. intermediate 3 min · from C file I/O cpp Quiz new Which declaration makes handler a pointer to a function that takes int and returns int? C23 function-pointer declarations, compatible types, callback context, and dispatch tables, including the casts and lifetime bugs to avoid. beginner 1 min · from C function pointers cpp Predict the output new What does this program print? C23 function-pointer declarations, compatible types, callback context, and dispatch tables, including the casts and lifetime bugs to avoid. beginner 2 min · from C function pointers cpp Quiz new An API retains a callback and void* context until unregister returns. Which context is sa… C23 function-pointer declarations, compatible types, callback context, and dispatch tables, including the casts and lifetime bugs to avoid. intermediate 1 min · from C function pointers cpp Review AI code new Review generated route registry C23 function-pointer declarations, compatible types, callback context, and dispatch tables, including the casts and lifetime bugs to avoid. advanced 6 min · from C function pointers cpp Spot the bug new Spot the bug in the qsort comparator C23 function-pointer declarations, compatible types, callback context, and dispatch tables, including the casts and lifetime bugs to avoid. intermediate 4 min · from C function pointers cpp Quiz new Which pointer may be passed to free? Manage sizes, ownership, and lifetimes with C23 allocation functions, using verifiable cleanup paths to prevent leaks, overflows, and use-after-free. intermediate 1 min · from C dynamic memory management cpp Predict the output new What does this C23 program print when calloc succeeds? Manage sizes, ownership, and lifetimes with C23 allocation functions, using verifiable cleanup paths to prevent leaks, overflows, and use-after-free. beginner 2 min · from C dynamic memory management cpp Quiz new What is guaranteed when realloc(owner, larger_size) returns NULL for a nonzero valid size? Manage sizes, ownership, and lifetimes with C23 allocation functions, using verifiable cleanup paths to prevent leaks, overflows, and use-after-free. intermediate 1 min · from C dynamic memory management cpp Review AI code new Review a generated byte buffer Manage sizes, ownership, and lifetimes with C23 allocation functions, using verifiable cleanup paths to prevent leaks, overflows, and use-after-free. advanced 6 min · from C dynamic memory management cpp Spot the bug new Spot the bug in array-copy allocation Manage sizes, ownership, and lifetimes with C23 allocation functions, using verifiable cleanup paths to prevent leaks, overflows, and use-after-free. intermediate 4 min · from C dynamic memory management cpp Quiz new What does const int *cursor permit? C pointers store object addresses; understand types, dereferencing, array bounds, lifetimes, and qualifiers to build contracts you can verify. beginner 1 min · from C pointers cpp Quiz new Inside void inspect(const int *values), what does sizeof(values) measure? C pointers store object addresses; understand types, dereferencing, array bounds, lifetimes, and qualifiers to build contracts you can verify. beginner 1 min · from C pointers cpp Predict the output new What does this program print? C pointers store object addresses; understand types, dereferencing, array bounds, lifetimes, and qualifiers to build contracts you can verify. beginner 2 min · from C pointers cpp Review AI code new Review a generated pointer-range search C pointers store object addresses; understand types, dereferencing, array bounds, lifetimes, and qualifiers to build contracts you can verify. advanced 6 min · from C pointers cpp Spot the bug new Spot the bug in the local reading pointer C pointers store object addresses; understand types, dereferencing, array bounds, lifetimes, and qualifiers to build contracts you can verify. beginner 4 min · from C pointers cpp Quiz new After #define CACHE_ENABLED 0, which condition selects the disabled branch? The C preprocessor expands macros, includes headers, and selects code before compilation; learn token replacement, configuration boundaries, and verifiable macros. beginner 1 min · from C preprocessor cpp Quiz new What does a conventional include guard guarantee? The C preprocessor expands macros, includes headers, and selects code before compilation; learn token replacement, configuration boundaries, and verifiable macros. beginner 1 min · from C preprocessor cpp Predict the output new What does this program print? The C preprocessor expands macros, includes headers, and selects code before compilation; learn token replacement, configuration boundaries, and verifiable macros. intermediate 2 min · from C preprocessor cpp Review AI code new Review a generated label-copy helper The C preprocessor expands macros, includes headers, and selects code before compilation; learn token replacement, configuration boundaries, and verifiable macros. advanced 7 min · from C preprocessor cpp Spot the bug new Spot the bug in the MAX_VALUE macro The C preprocessor expands macros, includes headers, and selects code before compilation; learn token replacement, configuration boundaries, and verifiable macros. intermediate 4 min · from C preprocessor cpp Quiz new A protocol byte is converted to enum MessageKind. What should happen before using it to i… Model records with structs, reuse storage with unions, and tag states with enums while keeping layout, copying, and active-member rules explicit. intermediate 1 min · from C structs, unions and enums cpp Predict the output new What does this program print? Model records with structs, reuse storage with unions, and tag states with enums while keeping layout, copying, and active-member rules explicit. beginner 2 min · from C structs, unions and enums cpp Review AI code new Review generated owned text message Model records with structs, reuse storage with unions, and tag states with enums while keeping layout, copying, and active-member rules explicit. advanced 6 min · from C structs, unions and enums cpp Spot the bug new Spot the bug in the tagged union Model records with structs, reuse storage with unions, and tag states with enums while keeping layout, copying, and active-member rules explicit. intermediate 4 min · from C structs, unions and enums cpp Quiz new Which statement about sizeof(struct Record) is portable C? Model records with structs, reuse storage with unions, and tag states with enums while keeping layout, copying, and active-member rules explicit. intermediate 1 min · from C structs, unions and enums cpp Quiz new What must a program track when a union represents several alternative payloads? Model records with structs, reuse storage with unions, and tag states with enums while keeping layout, copying, and active-member rules explicit. beginner 1 min · from C structs, unions and enums cpp Quiz new What language-level difference applies to otherwise identical class and struct definition… C++ classes package state and behavior into user-defined types; learn access control, construction, invariants, and compiler-generated special members. beginner 1 min · from Classes cpp Quiz new Why should a member function that only reads object state usually have a trailing const? C++ classes package state and behavior into user-defined types; learn access control, construction, invariants, and compiler-generated special members. beginner 1 min · from Classes cpp Predict the output new What does this program print? C++ classes package state and behavior into user-defined types; learn access control, construction, invariants, and compiler-generated special members. beginner 2 min · from Classes cpp Review AI code new Review generated course enrollment C++ classes package state and behavior into user-defined types; learn access control, construction, invariants, and compiler-generated special members. intermediate 6 min · from Classes cpp Spot the bug new Spot the bug in Invoice initialization C++ classes package state and behavior into user-defined types; learn access control, construction, invariants, and compiler-generated special members. intermediate 4 min · from Classes cpp Quiz new A constructor throws after two data members finished construction. Which destructors run? C++ exceptions separate error detection from handling; learn type matching, stack unwinding, RAII, safety guarantees, and truthful noexcept boundaries. intermediate 1 min · from Exceptions cpp Quiz new What happens when an exception tries to leave a noexcept function? C++ exceptions separate error detection from handling; learn type matching, stack unwinding, RAII, safety guarantees, and truthful noexcept boundaries. intermediate 1 min · from Exceptions cpp Predict the output new What does this program print? C++ exceptions separate error detection from handling; learn type matching, stack unwinding, RAII, safety guarantees, and truthful noexcept boundaries. intermediate 2 min · from Exceptions cpp Review AI code new Review generated ledger import C++ exceptions separate error detection from handling; learn type matching, stack unwinding, RAII, safety guarantees, and truthful noexcept boundaries. advanced 6 min · from Exceptions cpp Spot the bug new Spot the bug in record import cleanup C++ exceptions separate error detection from handling; learn type matching, stack unwinding, RAII, safety guarantees, and truthful noexcept boundaries. beginner 4 min · from Exceptions cpp Predict the output new What does this program print? C++ inheritance embeds a base subobject in a derived class and creates a substitutable type relationship; learn access, slicing, and virtual bases. intermediate 2 min · from Inheritance cpp Quiz new What does public inheritance guarantee about accessible base members? C++ inheritance embeds a base subobject in a derived class and creates a substitutable type relationship; learn access, slicing, and virtual bases. beginner 1 min · from Inheritance cpp Review AI code new Review generated report hierarchy C++ inheritance embeds a base subobject in a derived class and creates a substitutable type relationship; learn access, slicing, and virtual bases. advanced 6 min · from Inheritance cpp Spot the bug new Spot the bug in the job hierarchy C++ inheritance embeds a base subobject in a derived class and creates a substitutable type relationship; learn access, slicing, and virtual bases. intermediate 4 min · from Inheritance cpp Quiz new In a virtual-inheritance diamond, which constructor initializes the shared virtual base f… C++ inheritance embeds a base subobject in a derived class and creates a substitutable type relationship; learn access, slicing, and virtual bases. advanced 1 min · from Inheritance cpp Quiz new Why does constructing T from std::move(const_value) commonly call T(const T&) instead of … C++ move semantics through rvalue references, std::move, move operations, moved-from states, and noexcept-aware container behavior. intermediate 1 min · from Move semantics cpp Quiz new For a copyable type, when does std::move_if_noexcept return an rvalue reference? C++ move semantics through rvalue references, std::move, move operations, moved-from states, and noexcept-aware container behavior. advanced 1 min · from Move semantics cpp Predict the output new What does this program print? C++ move semantics through rvalue references, std::move, move operations, moved-from states, and noexcept-aware container behavior. intermediate 2 min · from Move semantics cpp Review AI code new Review generated Packet owner C++ move semantics through rvalue references, std::move, move operations, moved-from states, and noexcept-aware container behavior. advanced 6 min · from Move semantics cpp Spot the bug new Spot the bug in the moved-from vector C++ move semantics through rvalue references, std::move, move operations, moved-from states, and noexcept-aware container behavior. intermediate 4 min · from Move semantics cpp Predict the output new What does this program print? C++ namespaces organize names into scopes; understand qualified lookup, using declarations, ADL, and linkage boundaries to keep library APIs predictable. intermediate 2 min · from Namespaces cpp Review AI code new Review generated header label helper C++ namespaces organize names into scopes; understand qualified lookup, using declarations, ADL, and linkage boundaries to keep library APIs predictable. advanced 6 min · from Namespaces cpp Spot the bug new Spot the bug in the render definition C++ namespaces organize names into scopes; understand qualified lookup, using declarations, ADL, and linkage boundaries to keep library APIs predictable. intermediate 4 min · from Namespaces cpp Quiz new What happens to an unnamed-namespace variable defined in a header included by three trans… C++ namespaces organize names into scopes; understand qualified lookup, using declarations, ADL, and linkage boundaries to keep library APIs predictable. intermediate 1 min · from Namespaces cpp Quiz new Which statement best describes using metrics::distance; inside a function? C++ namespaces organize names into scopes; understand qualified lookup, using declarations, ADL, and linkage boundaries to keep library APIs predictable. beginner 1 min · from Namespaces cpp Quiz new In C++23, what happens when a class defines auto operator<=>(const T&) const = default; a… Operator overloading gives user-defined types natural C++ syntax; learn lookup, return types, and comparison contracts without semantic surprises. intermediate 1 min · from Operator overloading cpp Quiz new Why can an expression a + b find operator+ defined as a friend inside the class of a and … Operator overloading gives user-defined types natural C++ syntax; learn lookup, return types, and comparison contracts without semantic surprises. intermediate 1 min · from Operator overloading cpp Predict the output new What does this program print? Operator overloading gives user-defined types natural C++ syntax; learn lookup, return types, and comparison contracts without semantic surprises. beginner 2 min · from Operator overloading cpp Predict the output new What does this program print? Operator overloading gives user-defined types natural C++ syntax; learn lookup, return types, and comparison contracts without semantic surprises. intermediate 2 min · from Operator overloading cpp Review AI code new Review generated Polynomial class Operator overloading gives user-defined types natural C++ syntax; learn lookup, return types, and comparison contracts without semantic surprises. advanced 6 min · from Operator overloading cpp Spot the bug new Spot the bug in Scores indexing Operator overloading gives user-defined types natural C++ syntax; learn lookup, return types, and comparison contracts without semantic surprises. intermediate 4 min · from Operator overloading cpp Quiz new A resource-owning constructor throws after two RAII members finish construction. What is … RAII binds resource ownership to C++ object lifetime; learn deterministic destruction, exception paths, move-only owners, and non-throwing cleanup. intermediate 1 min · from RAII cpp Predict the output new What does this program print? RAII binds resource ownership to C++ object lifetime; learn deterministic destruction, exception paths, move-only owners, and non-throwing cleanup. intermediate 2 min · from RAII cpp Quiz new A function uses vector for all temporary memory but appends to its caller’s vector before… RAII binds resource ownership to C++ object lifetime; learn deterministic destruction, exception paths, move-only owners, and non-throwing cleanup. intermediate 1 min · from RAII cpp Review AI code new Repair a generated file owner RAII binds resource ownership to C++ object lifetime; learn deterministic destruction, exception paths, move-only owners, and non-throwing cleanup. advanced 6 min · from RAII cpp Spot the bug new Spot the bug in the Socket wrapper RAII binds resource ownership to C++ object lifetime; learn deterministic destruction, exception paths, move-only owners, and non-throwing cleanup. intermediate 4 min · from RAII cpp Quiz new Which declaration has a forwarding reference parameter? Bind expressions to existing objects with C++ references; understand lvalue and rvalue references, lifetimes, and forwarding without dangling. intermediate 1 min · from References cpp Predict the output new What does this program print? Bind expressions to existing objects with C++ references; understand lvalue and rvalue references, lifetimes, and forwarding without dangling. beginner 2 min · from References cpp Review AI code new Review a generated registry Bind expressions to existing objects with C++ references; understand lvalue and rvalue references, lifetimes, and forwarding without dangling. advanced 8 min · from References cpp Spot the bug new Spot the bug in the Result factory Bind expressions to existing objects with C++ references; understand lvalue and rvalue references, lifetimes, and forwarding without dangling. intermediate 4 min · from References cpp Quiz new A function stores a const std::string& parameter that was bound to a temporary argument. … Bind expressions to existing objects with C++ references; understand lvalue and rvalue references, lifetimes, and forwarding without dangling. intermediate 1 min · from References cpp Predict the output new What does this program print? Use unique_ptr for exclusive ownership and shared_ptr with weak_ptr for shared graphs, while avoiding control-block and lifetime bugs. beginner 2 min · from Smart pointers cpp Review AI code new Repair generated worker callbacks Use unique_ptr for exclusive ownership and shared_ptr with weak_ptr for shared graphs, while avoiding control-block and lifetime bugs. advanced 10 min · from Smart pointers cpp Quiz new What happens when a shared_ptr is copied? Use unique_ptr for exclusive ownership and shared_ptr with weak_ptr for shared graphs, while avoiding control-block and lifetime bugs. beginner 1 min · from Smart pointers cpp Quiz new Which C++23 statement about shared_ptr and threads is correct? Use unique_ptr for exclusive ownership and shared_ptr with weak_ptr for shared graphs, while avoiding control-block and lifetime bugs. advanced 1 min · from Smart pointers cpp Spot the bug new Spot the bug in the shared_ptr factory Use unique_ptr for exclusive ownership and shared_ptr with weak_ptr for shared graphs, while avoiding control-block and lifetime bugs. intermediate 4 min · from Smart pointers cpp Quiz new A Base constructor calls a virtual member on *this while constructing a Derived object. W… C++ virtual functions select an override from the dynamic type; learn pure virtual interfaces, safe destruction, and lifetime dispatch rules. intermediate 1 min · from Virtual functions cpp Quiz new After overload resolution selects a virtual member, what selects the function body for an… C++ virtual functions select an override from the dynamic type; learn pure virtual interfaces, safe destruction, and lifetime dispatch rules. intermediate 1 min · from Virtual functions cpp Predict the output new What does this program print? C++ virtual functions select an override from the dynamic type; learn pure virtual interfaces, safe destruction, and lifetime dispatch rules. advanced 2 min · from Virtual functions cpp Review AI code new Review a generated report interface C++ virtual functions select an override from the dynamic type; learn pure virtual interfaces, safe destruction, and lifetime dispatch rules. advanced 6 min · from Virtual functions cpp Spot the bug new Spot the bug in JsonDecoder override C++ virtual functions select an override from the dynamic type; learn pure virtual interfaces, safe destruction, and lifetime dispatch rules. intermediate 4 min · from Virtual functions