--- id: c-strings title: "C Strings" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["char array", "null terminator", "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: ["c", "programming-language", "w3schools", "strings"] raw_sources: ["https://www.w3schools.com/c/c_strings.php"] applied_in: [] github_commit: "" --- # [[C Strings]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) C has no true `String` type at all β€” a string is just an array of `char`s ending in a special `\0` null-terminator character, proven directly by the fact that `sizeof()` reports the SAME size (13 bytes) whether the string was written as a convenient literal (`"Hello World!"`) or manually spelled out character-by-character with an explicit `\0` at the end (`{'H','e',...,'!','\0'}`) β€” the literal syntax is pure convenience, not a different underlying type. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **No dedicated String type** β€” a C "string" is a `char` array; `char greetings[] = "Hello World!";` is the idiomatic way to create one. [S1] - **`%s` format specifier** β€” used to print an entire string (as opposed to `%c` for a single character). [S1] - **Index access** β€” since a string is an array, `greetings[0]` accesses its first character, printed with `%c`. [S1] - **Mutable characters** β€” individual characters can be reassigned via index (`greetings[0] = 'J';`), changing the string in place. [S1] - **Null terminator (`\0`)** β€” required at the end of a manually-built character-list string; string literals get it added automatically. [S1] - **Loop-through pattern** β€” iterating a string's characters via a `for` loop, ideally using `sizeof(arr)/sizeof(arr[0])` for the length instead of a hardcoded number. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Modifying a single character: `char greetings[] = "Hello World!"; greetings[0] = 'J'; printf("%s", greetings); // Outputs Jello World!`. [S1] - Manual character-list construction requiring an explicit null terminator: `char greetings[] = {'H','e','l','l','o',' ','W','o','r','l','d','!','\0'};`. [S1] - Proving both construction methods produce identically-sized arrays: `printf("%zu\n", sizeof(greetings)); // 13` and `printf("%zu\n", sizeof(greetings2)); // 13` (literal form auto-adds `\0`). [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **λ¬Έμžμ—΄ λ¦¬ν„°λŸ΄κ³Ό μˆ˜λ™ 문자 λ‚˜μ—΄μ˜ 동등성**: 두 방식 λͺ¨λ‘ κ²°κ΅­ λ™μΌν•œ 크기(13λ°”μ΄νŠΈ, \0 포함)의 char 배열을 λ§Œλ“ λ‹€λŠ” 점이 sizeof λΉ„κ΅λ‘œ 직접 증λͺ…됨 β€” λ¦¬ν„°λŸ΄μ€ 단지 \0을 μžλ™μœΌλ‘œ μΆ”κ°€ν•΄μ£ΌλŠ” 편의 문법일 뿐. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) 인사말과 이름을 μ‘°ν•©ν•΄ ν™˜μ˜ λ©”μ‹œμ§€λ₯Ό λ§Œλ“œλŠ” 예제(`"%s %s!", message, fname`)κ°€ μ›λ¬Έμ—μ„œ 직접 μ‹€μ „ ν™œμš© μ‚¬λ‘€λ‘œ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Looping through a string's characters using sizeof for a portable length calculation (C): ```c char carName[] = "Volvo"; int length = sizeof(carName) / sizeof(carName[0]); int i; for (i = 0; i < length; ++i) { printf("%c\n", carName[i]); } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.87 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[C Operators Precedence]], [[C Arrays]], [[C Strings Esc]] - **μ°Έμ‘° λ§₯락:** λ¬Έμžμ—΄ μ„Ήμ…˜ 첫 챕터 β€” 특수문자/μ΄μŠ€μΌ€μ΄ν”„(Strings Esc) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C Strings β€” https://www.w3schools.com/c/c_strings.php ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C Strings" page (Astra wiki-curation, P-Reinforce v3.1 format).