--- id: cpp-references title: "C++ References" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["reference variable", "alias", "& operator", "C++ μ°Έμ‘°"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.87 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["cpp", "programming-language", "w3schools", "references"] raw_sources: ["https://www.w3schools.com/cpp/cpp_references.asp"] applied_in: [] github_commit: "" --- # [[CPP References]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) A reference isn't a COPY or even a pointer to a variable β€” it's a genuine ALIAS, meaning `food` and `meal` in `string &meal = food;` are two DIFFERENT NAMES for the exact SAME memory location, so changing `meal` changes `food` directly with no dereference operator ever needed β€” a concept with NO equivalent in C, where the closest thing (a pointer) always requires explicit `*` to reach the value. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Reference variable (`type &alias = original;`)** β€” an alias for an EXISTING variable, created with the `&` operator at declaration. [S1] - **Same memory location** β€” the reference and the original variable refer to the identical memory address, not a copy. [S1] - **No dereference needed** β€” unlike a pointer, using a reference to read or write the value requires no `*`; you just use the reference name directly. [S1] - **Bidirectional change propagation** β€” changing either the original variable OR the reference changes the other, since they're the same storage. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Creating a reference and reading through both names: `string food = "Pizza"; string &meal = food; cout << food; // Pizza cout << meal; // Pizza`. [S1] - Changing through the reference affects the original: `meal = "Burger"; cout << food; // Burger cout << meal; // Burger`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **μ°Έμ‘°λŠ” C에 μ—†λ˜ μ™„μ „νžˆ μƒˆλ‘œμš΄ κ°œλ…**: ν¬μΈν„°μ²˜λŸΌ λ³„λ„μ˜ μ—­μ°Έμ‘°(*) μ—°μ‚° 없이도 원본 λ³€μˆ˜μ™€ μ™„μ „νžˆ λ™μΌν•œ λ©”λͺ¨λ¦¬λ₯Ό κ°€λ¦¬ν‚€λŠ” 별칭(alias)μ΄λΌλŠ” μ μ—μ„œ, C의 포인터와도 λ‹€λ₯Έ C++ 고유의 κ°œλ…μž„μ΄ 확인됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” μ°Έμ‘°λŠ” 이후 ν•¨μˆ˜ λ§€κ°œλ³€μˆ˜λ₯Ό κ°’ 볡사 없이 μ „λ‹¬ν•˜λŠ” μ‹€μ „ ν™œμš©(Function Reference 챕터)의 κΈ°μ΄ˆκ°€ λœλ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) A reference variable acting as a true alias β€” changing it changes the original directly (C++): ```cpp string food = "Pizza"; // food variable string &meal = food; // reference to food (an alias, not a copy) meal = "Burger"; // changes both meal and food cout << food; // Burger ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.87 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C++ Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CPP Enum]], [[CPP References Memory]], [[CPP Pointers]] - **μ°Έμ‘° λ§₯락:** 참쑰·포인터·메λͺ¨λ¦¬ μ„Ήμ…˜ 첫 챕터 β€” λ©”λͺ¨λ¦¬ μ£Όμ†Œ(References Memory) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C++ References β€” https://www.w3schools.com/cpp/cpp_references.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ References" page (Astra wiki-curation, P-Reinforce v3.1 format).