--- id: cpp-arrays title: "C++ Arrays" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["array declaration", "string arrays", "C++ λ°°μ—΄"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.85 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["cpp", "programming-language", "w3schools", "arrays"] raw_sources: ["https://www.w3schools.com/cpp/cpp_arrays.asp"] applied_in: [] github_commit: "" --- # [[CPP Arrays]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) C++ arrays can directly hold `string` elements (`string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};`) β€” something C could never do without manually nesting `char` arrays inside an outer array β€” meaning C++'s richer `string` type extends all the way into array element types, letting arrays of text behave as naturally as arrays of numbers. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Array declaration with size** β€” `type arrayName[size];` reserves space for `size` elements. [S1] - **Array literal initialization** β€” `{val1, val2, ...}` fills the array at declaration time. [S1] - **Zero-based indexing** β€” `[0]` is the first element. [S1] - **Mutable elements** β€” any element can be reassigned by index after creation. [S1] - **Arrays of `string`** β€” unlike C (which needs nested char arrays for text arrays), C++ arrays can hold `string` elements directly. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Declaring a string array with a literal: `string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};`. [S1] - Accessing an element: `cout << cars[0]; // Volvo`. [S1] - Modifying an element: `cars[0] = "Opel"; cout << cars[0]; // Now outputs Opel instead of Volvo`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **C++ 배열은 string을 직접 담을 수 있음**: Cμ—μ„œλŠ” λ¬Έμžμ—΄ 배열을 λ§Œλ“€λ €λ©΄ char 배열듀을 쀑첩해야 ν–ˆμ§€λ§Œ, C++μ—μ„œλŠ” string cars[4] = {...}처럼 λ°°μ—΄ μ›μ†Œλ‘œ string을 직접 μ‚¬μš©ν•  수 μžˆλ‹€λŠ” 점이 확인됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” μžλ™μ°¨ λΈŒλžœλ“œ λͺ©λ‘μ„ string λ°°μ—΄λ‘œ λ‹€λ£¨λŠ” μ˜ˆμ œκ°€ ν…μŠ€νŠΈ 데이터λ₯Ό λ°°μ—΄λ‘œ κ΄€λ¦¬ν•˜λŠ” μ‹€μ „ ν™œμš©μ˜ κΈ°μ΄ˆλ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) A string array β€” a text-array construction impossible directly in C (C++): ```cpp string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"}; cars[0] = "Opel"; cout << cars[0]; // Opel ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.85 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C++ Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CPP Break]], [[CPP Arrays Size]], [[C Arrays]] - **μ°Έμ‘° λ§₯락:** λ°°μ—΄ μ„Ήμ…˜ 첫 챕터 β€” λ°°μ—΄ 크기(Arrays Size) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C++ Arrays β€” https://www.w3schools.com/cpp/cpp_arrays.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Arrays" page (Astra wiki-curation, P-Reinforce v3.1 format).