--- id: c-debugging title: "C Debugging" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["print debugging", "breakpoints", "debugging vs error handling", "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: ["c", "programming-language", "w3schools", "debugging"] raw_sources: ["https://www.w3schools.com/c/c_debugging.php"] applied_in: [] github_commit: "" --- # [[C Debugging]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The chapter's closing distinction reframes debugging and error handling as two DIFFERENT PHASES of the same concern, not competing techniques: debugging is about finding/fixing mistakes DURING DEVELOPMENT, while error handling is about gracefully responding to problems WHILE THE PROGRAM RUNS in production β€” meaning a well-built C program needs both, applied at different times, not one instead of the other. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Print debugging** β€” sprinkling `printf()` calls to trace how far execution gets before something goes wrong; if an expected message never prints, the crash happened before that line. [S1] - **Checking variable values** β€” printing intermediate results to catch LOGIC errors (e.g. expecting 15 but getting 5 reveals a wrong operator, not a crash). [S1] - **IDE debuggers** β€” breakpoints, line-by-line stepping, and variable-watching, available in IDEs like Visual Studio/Code::Blocks/VS Code; recommended as a step UP from `printf()` debugging once comfortable with the basics. [S1] - **Reading error messages literally** β€” the compiler/runtime often states exactly what's wrong and where (e.g. `expected ';' before 'printf'` β†’ the fix is adding the missing semicolon). [S1] - **Defensive checks preventing crashes** β€” proactively checking conditions that are KNOWN to cause crashes (e.g. `if (y != 0)` before dividing, `if (index >= 0 && index < 3)` before array access) converts a crash into a graceful error message. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Print debugging locating a crash point: `printf("Before division\n"); int z = x / y; printf("After division\n");` β€” if "After division" never prints, the crash happened at the division. [S1] - Logic-error detection via variable printing: `int result = x - y; printf("Result: %d\n", result); // Result: 5 (expected 15 β€” wrong operator used)`. [S1] - Preventing a divide-by-zero crash with a defensive check: `if (y != 0) { int z = x / y; printf("Result: %d\n", z); } else { printf("Error: Division by zero!\n"); }`. [S1] - Preventing an out-of-bounds crash with a defensive check: `if (index >= 0 && index < 3) { printf("Value = %d\n", numbers[index]); } else { printf("Error: Index out of bounds!\n"); }`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **디버깅과 μ—λŸ¬ μ²˜λ¦¬λŠ” μ„œλ‘œ λ‹€λ₯Έ 단계**: 디버깅은 개발 쀑 버그λ₯Ό μ°Ύκ³  κ³ μΉ˜λŠ” ν™œλ™μ΄κ³ , μ—λŸ¬ μ²˜λ¦¬λŠ” ν”„λ‘œκ·Έλž¨μ΄ μ‹€μ œλ‘œ μ‹€ν–‰λ˜λŠ” 쀑 λ¬Έμ œμ— λŒ€μ‘ν•˜λŠ” κ²ƒμ΄λΌλŠ” 점이 λͺ…ν™•νžˆ κ΅¬λΆ„λ˜λ©°, λ‘˜ λ‹€ ν•„μš”ν•˜λ‹€λŠ” 점이 결둠으둜 μ œμ‹œλ¨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) 0으둜 λ‚˜λˆ„κΈ°μ™€ λ°°μ—΄ λ²”μœ„ 초과 μ ‘κ·Όμ΄λΌλŠ” 두 κ°€μ§€ λŒ€ν‘œμ  ν¬λž˜μ‹œ 상황을 사전 쑰건 κ²€μ‚¬λ‘œ λ°©μ§€ν•˜λŠ” 방법이 μ›λ¬Έμ—μ„œ 직접 μ‹€μ „ ν™œμš© μ‚¬λ‘€λ‘œ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Preventing a division-by-zero crash with a defensive check instead of a printf-based fix (C): ```c int x = 10; int y = 0; if (y != 0) { int z = x / y; printf("Result: %d\n", z); } else { printf("Error: Division by zero!\n"); } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.85 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[C Input Validation]], [[C Errors]], [[C Files]] - **μ°Έμ‘° λ§₯락:** μ—λŸ¬ 및 디버깅 μ„Ήμ…˜ λ§ˆμ§€λ§‰ β€” 파일 μž…μΆœλ ₯(Files) μ„Ήμ…˜μœΌλ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C Debugging β€” https://www.w3schools.com/c/c_debugging.php ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C Debugging" page (Astra wiki-curation, P-Reinforce v3.1 format).