Flashcards · C++ · Free
C++ flashcards, generated for you.
Example C++ study cards to learn from right now — then generate a full set from your own notes (plus a practice quiz) and export to Quizlet or Anki. Free, no account needed.
Example C++ flashcards
What is the difference between declaring a variable and defining it in C++?
Declaration tells the compiler about a variable's type and name (e.g., `extern int x;`). Definition allocates storage and optionally initializes it (e.g., `int x = 5;`). A definition is also a declaration, but not vice versa.
What does `nullptr` do, and why is it preferred over `NULL`?
`nullptr` is a null pointer constant with type `std::nullptr_t`. It's type-safe and prevents accidental implicit conversions to integers. `NULL` is often just `0`, which can cause overload ambiguity.
Explain the difference between `std::string str = "hello";` and `std::string str{"hello"};`
Both initialize `str` to "hello". The first uses copy-initialization; the second uses brace-initialization (uniform initialization). Brace-initialization prevents narrowing conversions and is generally preferred in modern C++.
What is the difference between a reference and a pointer in C++?
References are non-null aliases to existing objects (cannot be reassigned or reseated), require initialization at declaration, and use dot notation. Pointers are variables storing addresses, can be null, can be reassigned, and use arrow (`->`) or dereference (`*`) notation.
What does `const` mean when placed before vs. after the `*` in `int* const` vs. `const int*`?
`const int*` (or `int const*`): pointer to a const int—the pointed-to value cannot change. `int* const`: const pointer to an int—the pointer address cannot change, but the value can.
What is RAII and why is it important in C++?
Resource Acquisition Is Initialization: resources (memory, files, locks) are tied to object lifetime—acquired in constructor, released in destructor. This ensures automatic cleanup even if exceptions occur, preventing leaks and resource exhaustion.
What's the key difference between pass-by-value, pass-by-reference, and pass-by-const-reference?
Pass-by-value: copies the object (overhead, modifications don't affect original). Pass-by-reference: aliases the object (fast, modifications affect original, caller must pass lvalue). Pass-by-const-reference: fast, read-only, accepts both lvalues and rvalues—preferred for large objects.
Why does `std::vector::resize(n)` differ from `std::vector::reserve(n)`?
`resize(n)` changes the logical size and adds/removes elements (calling constructors/destructors as needed). `reserve(n)` only preallocates capacity without changing size. Use `reserve()` to avoid reallocations during repeated `push_back()`.
What is move semantics and when is a move constructor invoked instead of a copy constructor?
Move semantics transfers ownership of resources (like heap memory) from a temporary object to another, avoiding deep copies. A move constructor is invoked when binding to an rvalue (temporary), detected via `&&`. Use `std::move()` to cast lvalues to rvalues.
What is the 'most vexing parse' and how do you avoid it?
The parser interprets `MyClass obj(SomeType());` as a function declaration, not object construction. Avoid it using brace-initialization: `MyClass obj{SomeType()};` or explicit parentheses: `MyClass obj((SomeType()));`
Make your own C++ study set
Flashcards for related topics
Studying C++ to build with AI? MindloomHQ turns it into real skills — structured courses, agent projects, and certificates.
Explore MindloomHQ →