--- id: cpp-errors title: "C++ Errors" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["compile-time vs runtime errors", "dangling pointer", "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", "errors"] raw_sources: ["https://www.w3schools.com/cpp/cpp_errors.asp"] applied_in: [] github_commit: "" --- # [[CPP Errors]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The three runtime error examples (divide-by-zero, out-of-bounds array access, using DELETED memory via a dangling pointer) all share the same trait as C's equivalent chapter β€” none are caught at compile time, all three compile cleanly and only misbehave when actually executed β€” but C++'s third example specifically involves `new`/`delete` (`int* ptr = new int(10); delete ptr; cout << *ptr;`), a "dangling pointer" scenario that has no direct C equivalent since C's version used plain `malloc`/`free`. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Compile-time errors** β€” prevent compilation entirely; e.g. missing semicolon, undeclared variable, type mismatch (`invalid conversion from 'const char*' to 'int'`). [S1] - **Runtime errors** β€” the program compiles but crashes/misbehaves when RUN; e.g. division by zero, out-of-bounds array access, dangling pointer (reading memory after `delete`). [S1] - **Dangling pointer** β€” a pointer that still holds an address after that memory was `delete`d; dereferencing it (`*ptr`) is invalid, C++-specific terminology tied to `new`/`delete`. [S1] - **Good habits** β€” initialize variables, use meaningful names, keep indentation clean, keep functions short/focused, verify loop/condition behavior, read error messages carefully. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Type mismatch error message (more specific than C's generic phrasing): `int x = "Hello"; // error: invalid conversion from 'const char*' to 'int'`. [S1] - Dangling pointer, a C++-specific runtime error: `int* ptr = new int(10); delete ptr; cout << *ptr; // invalid β€” dereferencing freed memory`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **λŒ•κΈ€λ§ ν¬μΈν„°λŠ” new/delete와 κ²°ν•©λœ C++ 특유의 ν‘œν˜„**: C의 use-after-free μ˜ˆμ œκ°€ malloc/free κΈ°λ°˜μ΄μ—ˆλ‹€λ©΄, C++μ—μ„œλŠ” new/delete와 κ²°ν•©λœ "λŒ•κΈ€λ§ 포인터"λΌλŠ” ꡬ체적 μš©μ–΄λ‘œ λ™μΌν•œ λ¬Έμ œκ°€ μž¬ν™•μΈλ¨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” 컴파일 νƒ€μž„ μ—λŸ¬ 3μ’…κ³Ό λŸ°νƒ€μž„ μ—λŸ¬ 3쒅을 λ‚˜λž€νžˆ λŒ€λΉ„μ‹œν‚¨ 것이 두 μ—λŸ¬ λ²”μ£Όμ˜ 근본적 차이λ₯Ό μ΄ν•΄ν•˜λŠ” μ‹€μ „ ν•™μŠ΅ 자료둜 ν™œμš©λœλ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Using memory after it's been deleted β€” a dangling pointer, compiles fine but is invalid at runtime (C++): ```cpp int* ptr = new int(10); delete ptr; cout << *ptr; // invalid β€” dangling pointer ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.85 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C++ Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CPP Date]], [[CPP Memory Management New]], [[CPP Exceptions]] - **μ°Έμ‘° λ§₯락:** μ—λŸ¬ μ„Ήμ…˜ 첫 챕터 β€” μ˜ˆμ™Έ 처리(Exceptions) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C++ Errors β€” https://www.w3schools.com/cpp/cpp_errors.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Errors" page (Astra wiki-curation, P-Reinforce v3.1 format).