Skip to content

C++ Types and Resource Management: Practice Problems

C++ Types and Resource Management — Practice Problems

17 practice problems covering fundamental C++ concepts: types, RAII, ownership, move semantics, smart pointers, and undefined behavior.


Basic Types and References

Ownership and RAII

Smart Pointers

Move Semantics and Undefined Behavior

Advanced Ownership and Resource Management


TopicSiteLink
Resource ManagementProgrammingResource Management
TemplatesProgrammingTemplates & Metaprogramming
Rust OwnershipLanguagesRust Ownership
C++ ConcurrencyProgrammingConcurrency

Common Mistakes

Confusing value semantics with reference semantics: In C++, structs and classes passed by value are copied, not shared. Modifying the copy does not affect the original. Passing by reference or pointer shares the original. Forgetting this leads to bugs where changes “disappear” because they were applied to a copy.

Using const incorrectly with pointers: const int* p means the pointed-to int is const (pointer can change). int* const p means the pointer itself is const (pointed-to int can change). const int* const p means both are const. The position of const relative to * determines what is constant — a common source of confusion.

Assuming smart pointers eliminate all memory concerns: Smart pointers prevent leaks from forgotten deletes, but they do not prevent circular references (shared_ptr cycles), premature destruction, or incorrect deleter usage. Understanding ownership semantics is still essential even with smart pointers.

See Also