Add remaining flashcards and reference files (qn_01, segment_tree, ds, learning)

This commit is contained in:
2026-05-26 01:30:51 +08:00
parent fa64e776ca
commit f603236a48
10 changed files with 639 additions and 14 deletions
@@ -0,0 +1,20 @@
# C++ Pointers and References - Mastery Checklist
## Core Concepts
Track your understanding of key concepts:
- [ ] Declaration syntax: & and * placement
- [ ] Pointers vs references: mental model
- [ ] Pointer arithmetic
- [ ] const correctness with pointers and references
- [ ] References as function parameters
- [ ] Pointer-to-pointer
- [ ] Null pointers and nullptr
- [ ] Dangling pointers and references
- [ ] Smart pointers (unique_ptr, shared_ptr, weak_ptr)
- [ ] Lvalue references vs rvalue references
- [ ] Move semantics
- [ ] Perfect forwarding
- [ ] Reference collapsing rules
- [ ] Common interview traps
@@ -0,0 +1,9 @@
{
"topic": "C++ Pointers and References",
"created_at": "2026-05-20T12:00:00",
"status": "in_progress",
"syllabus_generated": true,
"total_sessions": 0,
"last_session": null,
"last_reviewed": null
}
@@ -0,0 +1,5 @@
# C++ Pointers and References - Learning Progress
## Daily Logs
<!-- Daily learning entries will be added here -->
@@ -0,0 +1,3 @@
{
"reviews": []
}
@@ -0,0 +1,86 @@
# C++ Pointers and References — Syllabus
## Overview
Master C++ indirection mechanisms from declaration syntax through move semantics. Emphasis on building correct mental models, real-world usage patterns, and surviving interview questions about pointers and references.
## Prerequisites
- Basic C++ syntax (variables, functions, structs/classes)
- Understanding of stack vs heap (conceptual)
## Learning Objectives
By completion you will be able to:
- Read and write any pointer/reference declaration confidently
- Explain the difference between `&`/`*` in declarations vs expressions
- Use const-correctness with pointers and references correctly
- Understand ownership semantics and choose the right smart pointer
- Handle move semantics and forwarding references
- Answer common interview questions on pointers and references
---
## Phase 1: Foundations — Declaration Syntax & Mental Models
- [ ] `&` and `*` in declarations vs expressions — the two contexts
- [ ] Does `*` / `&` bind to the type or the variable? (C++ parsing rules)
- [ ] Multiple declarations on one line: `int *a, b` — what is b?
- [ ] Pointers: what they are (address), what they hold, how to dereference
- [ ] References: what they are (alias), how they differ from pointers
- [ ] Pointer vs reference: when to use which (guidelines)
- [ ] Null pointers: NULL vs nullptr vs 0
**Teaching Milestone:** Explain the "declaration follows use" principle to a beginner.
## Phase 2: const Correctness & Function Signatures
- [ ] `const int*` vs `int* const` vs `const int* const`
- [ ] `const int&` — why it's the default parameter style
- [ ] Top-level const vs low-level const
- [ ] East const vs West const style
- [ ] Passing by value vs by reference vs by pointer — tradeoffs
- [ ] Return by reference: when safe, when dangerous
- [ ] Pointer arithmetic basics
**Teaching Milestone:** Read a complex function signature and explain what each parameter accepts and whether it can be modified.
## Phase 3: Ownership & Smart Pointers
- [ ] Raw pointer ownership problems (leaks, double free, dangling)
- [ ] RAII principle
- [ ] `std::unique_ptr` — exclusive ownership
- [ ] `std::shared_ptr` — shared ownership and reference counting
- [ ] `std::weak_ptr` — breaking cycles
- [ ] Choosing the right smart pointer (decision tree)
- [ ] `std::make_unique` / `std::make_shared` — why prefer them
**Teaching Milestone:** Refactor a raw-pointer design to use smart pointers and explain your choices.
## Phase 4: Move Semantics & Advanced References
- [ ] Lvalue vs rvalue — what are they really
- [ ] Lvalue references (`T&`) vs rvalue references (`T&&`)
- [ ] `std::move` — what it does and doesn't do
- [ ] Move constructors and move assignment
- [ ] Reference collapsing rules
- [ ] Forwarding references (`T&&` in templates)
- [ ] `std::forward` — perfect forwarding
- [ ] Common interview traps and trick questions
**Teaching Milestone:** Explain why `std::move` doesn't actually move anything.
---
## Resources
- cppreference.com — authoritative reference
- "Effective Modern C++" by Scott Meyers — Items 1-6, 23-26
- Herb Sutter's GotW articles on const correctness
## Success Criteria
- Can read any declaration with `*`, `&`, `const` and explain it
- Can choose between pointer, reference, and smart pointer for any use case
- Can explain move semantics without hand-waving
- Can spot pointer/reference bugs in code review