1cfd3bbb56
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고, Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
74 lines
4.0 KiB
Markdown
74 lines
4.0 KiB
Markdown
---
|
|
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).
|