--- id: c-enums title: "C Enumeration (enum)" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["enum keyword", "named constants", "C μ—΄κ±°ν˜•"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.86 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["c", "programming-language", "w3schools", "enums"] raw_sources: ["https://www.w3schools.com/c/c_enums.php"] applied_in: [] github_commit: "" --- # [[C Enumeration (enum)]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Assigning an explicit value to just ONE enum item cascades forward β€” `enum Level { LOW = 5, MEDIUM, HIGH };` gives `MEDIUM` the value 6 and `HIGH` the value 7 automatically, without being written explicitly β€” meaning enum numbering isn't independently assigned per item by default; each unlabeled item simply continues incrementing from whatever the PRECEDING item's value was. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`enum`** β€” a type representing a group of named, unchangeable constants ("specifically listed" values). [S1] - **Default numbering** β€” the first item is 0, the second 1, and so on, unless overridden. [S1] - **Forward-cascading custom values** β€” setting one item's value shifts all SUBSEQUENT unlabeled items to continue counting up from it. [S1] - **Enum as an int under the hood** β€” printing an enum variable with `%d` shows its underlying integer value, enabling direct use in `switch` statements matched against those integers. [S1] - **`typedef` with enum** β€” eliminates needing to write `enum` before the type name every time a variable is declared, a pure readability/brevity improvement. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Default numbering: `enum Level { LOW, MEDIUM, HIGH }; enum Level myVar = MEDIUM; printf("%d", myVar); // 1`. [S1] - Fully custom values: `enum Level { LOW = 25, MEDIUM = 50, HIGH = 75 };`. [S1] - Cascading from one custom value: `enum Level { LOW = 5, MEDIUM, HIGH };` β€” MEDIUM becomes 6, HIGH becomes 7. [S1] - Enum used in a switch: `enum Level myVar = MEDIUM; switch (myVar) { case 1: ... case 2: ... case 3: ... }` (matching against LOW=1, MEDIUM=2, HIGH=3). [S1] - typedef shortcut: `typedef enum {MON, TUE, WED, THU, FRI, SAT, SUN} Day; Day today = WED;` instead of `enum Day today = WED;`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **ν•˜λ‚˜μ˜ κ°’ 지정이 이후 ν•­λͺ©κΉŒμ§€ μ—°μ‡„μ μœΌλ‘œ 영ν–₯**: LOW = 5둜 μ§€μ •ν•˜λ©΄ λ’€λ”°λ₯΄λŠ” MEDIUM, HIGHλŠ” λͺ…μ‹œν•˜μ§€ μ•Šμ•„λ„ μžλ™μœΌλ‘œ 6, 7이 λœλ‹€λŠ” 점이 λͺ…ν™•νžˆ 확인됨 β€” 각 ν•­λͺ©μ΄ λ…λ¦½μ μœΌλ‘œ 0λΆ€ν„° μž¬μ‹œμž‘ν•˜λŠ” 것이 μ•„λ‹˜. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) μš”μΌ(Day)μ΄λ‚˜ μ›”κ³Ό 같이 μ ˆλŒ€ λ³€ν•˜μ§€ μ•ŠλŠ” κ°’ 집합에 enum을 μ‚¬μš©ν•˜λŠ” 것이 μ‹€μ „ ν™œμš©μ˜ λŒ€ν‘œ μ‚¬λ‘€λ‘œ 원문에 직접 μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Setting one enum value causes subsequent items to cascade forward from it (C): ```c enum Level { LOW = 5, MEDIUM, // Now 6 HIGH // Now 7 }; ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.86 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[C Structs Pointers]], [[C Switch]], [[C Unions]], [[C Typedef]] - **μ°Έμ‘° λ§₯락:** μ—΄κ±°ν˜• β€” μœ λ‹ˆμ˜¨(Unions) μ±•ν„°λ‘œ 이어짐, typedef 챕터와 직접 μ—°κ²°. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C Enumeration (enum) β€” https://www.w3schools.com/c/c_enums.php ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C Enumeration (enum)" page (Astra wiki-curation, P-Reinforce v3.1 format).