From ffdbb39158d53f87bafd8eee51c539e64f97ee83 Mon Sep 17 00:00:00 2001 From: Wong Ding Feng Date: Wed, 22 Apr 2026 23:23:33 +0800 Subject: [PATCH] chore: sync Anki note IDs for arrays-and-refs flashcards Adds ANKI_NOTE_ID properties after syncing cards to Anki deck. Minor table alignment reformatting from the sync process. Co-Authored-By: Claude Sonnet 4.6 --- org/cpp/arrays-and-refs.org | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/org/cpp/arrays-and-refs.org b/org/cpp/arrays-and-refs.org index 26dd16d..ac12c27 100644 --- a/org/cpp/arrays-and-refs.org +++ b/org/cpp/arrays-and-refs.org @@ -1,6 +1,7 @@ * Why can't you return a raw C-style array :cpp:arrays:elaborative-why: :PROPERTIES: :ANKI_NOTE_TYPE: Basic +:ANKI_NOTE_ID: 1776793508138 :END: ** Front Why is returning a raw C-style array illegal in C++? @@ -15,23 +16,25 @@ return arr; // ❌ returns pointer to dead stack memory * std::array vs int[]: key differences :cpp:arrays:comparative: :PROPERTIES: :ANKI_NOTE_TYPE: Basic +:ANKI_NOTE_ID: 1776793508134 :END: ** Front How does ~std::array~ differ from ~int[26]~? ** Back | Feature | ~int[26]~ | ~std::array~ | -|----------------------+-----------+---------------------| -| Return by value | No | Yes | -| Copy/assign | No | Yes | -| Knows its own size | No | ~.size()~ | -| Works with STL algos | No | Yes | -| Zero-init with ~{}~ | No | Yes | +|----------------------+---------+--------------------| +| Return by value | No | Yes | +| Copy/assign | No | Yes | +| Knows its own size | No | ~.size()~ | +| Works with STL algos | No | Yes | +| Zero-init with ~{}~ | No | Yes | Same machine code — zero overhead. * Task: return character frequency count from string :cpp:arrays:production: :PROPERTIES: :ANKI_NOTE_TYPE: Basic +:ANKI_NOTE_ID: 1776793508129 :END: ** Front Write a function that counts character frequencies in a string and returns the result. The string has only lowercase letters. @@ -49,6 +52,7 @@ std::array calc(const std::string& str) { * Stack vs heap: std::array vs std::vector :cpp:arrays:comparative: :PROPERTIES: :ANKI_NOTE_TYPE: Basic +:ANKI_NOTE_ID: 1776793508124 :END: ** Front Where is the data stored for ~std::array~ vs ~std::vector(26)~? @@ -61,6 +65,7 @@ Rule: use ~std::array~ when size is known at compile time (fast, no alloc). Use * Why const in const T& parameter :cpp:references:elaborative-why: :PROPERTIES: :ANKI_NOTE_TYPE: Basic +:ANKI_NOTE_ID: 1776793508119 :END: ** Front Why write ~const std::string&~ instead of ~std::string&~ for a read-only parameter? @@ -79,6 +84,7 @@ calc(s); // ❌ without const * Why & instead of pass-by-value for string param :cpp:references:elaborative-why: :PROPERTIES: :ANKI_NOTE_TYPE: Basic +:ANKI_NOTE_ID: 1776793508114 :END: ** Front Why pass ~std::string~ by reference (~const std::string&~) instead of by value? @@ -95,21 +101,23 @@ For a function that only reads, the copy is pure waste. * Reference vs pointer for function parameters :cpp:references:comparative: :PROPERTIES: :ANKI_NOTE_TYPE: Basic +:ANKI_NOTE_ID: 1776793508109 :END: ** Front When do you use ~T&~ vs ~T*~ for a function parameter? ** Back -| Feature | Reference ~T&~ | Pointer ~T*~ | -|-------------------+----------------+--------------------| -| Can be null | No | Yes | -| Dereference | ~str[i]~ | ~(*str)[i]~ | -| Can be reassigned | No | Yes | +| Feature | Reference ~T&~ | Pointer ~T*~ | +|-------------------+--------------+------------| +| Can be null | No | Yes | +| Dereference | ~str[i]~ | ~(*str)[i]~ | +| Can be reassigned | No | Yes | Use ~T*~ when null is a valid input. Use ~T&~ when the value is *guaranteed to exist* — which is almost always the case for function parameters. * Rule of thumb: C++ function parameter types :cpp:references:factual: :PROPERTIES: :ANKI_NOTE_TYPE: Basic +:ANKI_NOTE_ID: 1776793508102 :END: ** Front What's the general rule for choosing parameter types in C++ functions?