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 `int x;` and `int x = 0;` in C++?
`int x;` creates an uninitialized variable with garbage value. `int x = 0;` explicitly initializes it to 0. Use `int x{};` (uniform initialization) to safely default-initialize.
What does `const` mean when placed before vs. after the `*` in `const int* p` vs. `int* const p`?
`const int* p`: pointer to a constant int (data is const, pointer can move). `int* const p`: constant pointer to int (pointer is const, data can change).
What is the difference between passing by value, reference, and const reference?
By value: copy made (slow for large objects). By reference `&`: alias to original (allows modification). By const reference `const&`: alias to original (read-only, efficient).
What happens if you forget to write `return` in a function?
Function returns undefined/garbage value (for non-void types). Compiler may warn but won't error. Always explicitly return or use `void`.
What is the difference between `vector<int> v(5)` and `vector<int> v{5}`?
`v(5)` creates vector of 5 default-initialized ints (size 5). `v{5}` creates vector with single element 5 (size 1). Uniform initialization `{}` can be confusing—prefer `v.resize(5)` for clarity.
What is undefined behavior and why is it dangerous in C++?
Code with undefined behavior has no guaranteed outcome—may crash, appear to work, or behave unpredictably. Common causes: null pointer dereference, out-of-bounds access, use-after-free. Compiler makes no promises.
What is the difference between `delete p` and `delete[] p`?
`delete p` deallocates single object. `delete[] p` deallocates array. Using wrong form causes heap corruption. Use `std::unique_ptr` or `std::vector` to avoid manual management.
Why does `std::string s = "hello"; s[10];` not throw an exception?
`operator[]` does not bounds-check (undefined behavior if out of range). Use `.at()` instead, which throws `std::out_of_range` exception. Always use `.at()` for safety-critical code.
What is RAII and why is it important in C++?
Resource Acquisition Is Initialization: resources (memory, files, locks) are acquired in constructor and released in destructor. Ensures cleanup even if exceptions occur. Use smart pointers and container classes.
What does `std::move()` do and when should you use it?
`std::move()` casts an lvalue to an rvalue, enabling move semantics (steal resources instead of copy). Use when passing temporary objects or explicitly transferring ownership: `vec.push_back(std::move(obj));`
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 →