--- id: c-operators-logical title: "C Logical Operators" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["&& || !", "logical AND OR NOT", "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", "operators", "logical"] raw_sources: ["https://www.w3schools.com/c/c_operators_logical.php"] applied_in: [] github_commit: "" --- # [[C Logical Operators]] ## 🎯 한 줄 통찰 (One-line insight) The login-check example combines a comparison-like value (`isLoggedIn`) with its NEGATION (`!isAdmin`) inside a single `&&` expression (`isLoggedIn && !isAdmin` = "regular user") — showing that logical operators aren't just for combining two independent conditions, but are routinely used to express compound business rules like "authenticated AND NOT privileged" as one evaluable expression. [S1] ## 🧠 핵심 개념 (Core concepts) - **`&&` (AND)** — returns 1 only if BOTH operands are true. [S1] - **`||` (OR)** — returns 1 if AT LEAST ONE operand is true. [S1] - **`!` (NOT)** — reverses the result: 1 becomes 0, 0 becomes 1. [S1] - **1 = true, 0 = false** — the same convention as Comparison Operators; logical operators combine these int-valued truth results. [S1] ## 📖 세부 내용 (Details) - Login/permission check combining AND and NOT: `int isLoggedIn = 1; int isAdmin = 0; printf("Regular user: %d\n", isLoggedIn && !isAdmin); printf("Has access: %d\n", isLoggedIn || isAdmin); printf("Not logged in: %d\n", !isLoggedIn);` — outputs `1`, `1`, `0` respectively. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) - 현재까지 발견된 모순 사항 없음 (No contradictions found in available sources). ## 🛠️ 적용 사례 (Applied in summary) 로그인 여부와 관리자 권한을 조합해 "일반 사용자인지", "접근 권한이 있는지"를 판단하는 예제가 원문에서 직접 실전 활용 사례로 제시됨(인증/인가 로직의 기초). [S1] ## 💻 코드 패턴 (Code patterns) Combining AND and NOT to express a compound access-control rule (C): ```c int isLoggedIn = 1; int isAdmin = 0; printf("Regular user: %d\n", isLoggedIn && !isAdmin); // 1 printf("Has access: %d\n", isLoggedIn || isAdmin); // 1 printf("Not logged in: %d\n", !isLoggedIn); // 0 ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.85 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[C Tutorial]] - **관련 개념:** [[C Operators Comparison]], [[C Bitwise Operators]], [[C Conditions Logical]] - **참조 맥락:** 논리 연산자 — 비트 연산자(Bitwise Operators) 챕터로 이어짐, 조건문의 논리 연산(Conditions Logical) 챕터와 직접 연결. ## 📚 출처 (Sources) - [S1] W3Schools — C Logical Operators — https://www.w3schools.com/c/c_operators_logical.php ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C Logical Operators" page (Astra wiki-curation, P-Reinforce v3.1 format).