---
id: c-type-conversion
title: "C Type Conversion"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["implicit conversion", "explicit conversion", "casting", "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", "type-conversion", "casting"]
raw_sources: ["https://www.w3schools.com/c/c_type_conversion.php"]
applied_in: []
github_commit: ""
---

# [[C Type Conversion]]

## 🎯 한 줄 통찰 (One-line insight)
Casting the RESULT of a division after the fact doesn't fix precision loss — `float sum = 5 / 2;` still prints `2.000000` because `5 / 2` is computed as INTEGER division BEFORE ever being assigned to `sum` — the cast must be applied to an OPERAND inside the division itself (`(float) 5 / 2`), proving that explicit conversion timing matters as much as the conversion existing at all. [S1]

## 🧠 핵심 개념 (Core concepts)
- **Type conversion** — converting a value from one data type to another, either automatically (implicit) or manually (explicit). [S1]
- **Implicit conversion** — done automatically by the compiler (e.g. assigning `int` to `float`); risky in the REVERSE direction, since assigning `float` to `int` silently TRUNCATES the decimal part with no warning. [S1]
- **Explicit conversion (casting)** — manually placing a type in parentheses `(type)` before a value or variable to force conversion at a SPECIFIC point in an expression. [S1]
- **Casting must happen INSIDE the expression, not after** — `float sum = 5 / 2;` still integer-divides first (yielding 2.000000); only `float sum = (float) 5 / 2;` produces the correct 2.5, because casting one operand to `float` before the division forces the WHOLE division to be floating-point. [S1]

## 📖 세부 내용 (Details)
- Implicit int-to-float (safe direction): `float myFloat = 9; // 9.000000`. [S1]
- Implicit float-to-int (risky, silently truncates): `int myInt = 9.99; // 9, the .99 is silently lost`. [S1]
- The casting-timing trap: `float sum = 5 / 2; // still 2.000000 — integer division happens BEFORE assignment`. [S1]
- The correct fix — casting an operand INSIDE the division: `float sum = (float) 5 / 2; // 2.500000`. [S1]
- Cleaning up the display with decimal precision: `printf("%.1f", sum); // 2.5`. [S1]
- Real-life percentage calculation combining casting with arithmetic: `int maxScore = 500; int userScore = 423; float percentage = (float) userScore / maxScore * 100.0; printf("User's percentage is %.2f", percentage);`. [S1]

## ⚖️ 모순 및 업데이트 (Contradictions & updates)
- **결과가 아닌 피연산자에 캐스팅해야 함**: float sum = 5 / 2;처럼 결과 변수만 float로 선언해서는 정수 나눗셈이 먼저 일어나 여전히 2.000000이 나오며, (float) 5 / 2처럼 나눗셈 안의 피연산자를 캐스팅해야만 올바른 2.5가 나온다는 점이 명확히 대비됨. [S1]
- **암묵적 float→int 변환은 소수점을 조용히 버림**: 9.99를 int에 대입하면 경고 없이 9가 되어 .99가 사라진다는 점이 위험 요소로 명시됨. [S1]

## 🛠️ 적용 사례 (Applied in summary)
게임 점수(423/500)를 백분율로 정확히 계산하기 위해 userScore를 float로 캐스팅한 뒤 나누는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1]

## 💻 코드 패턴 (Code patterns)
Casting an operand inside the division to force floating-point arithmetic (C):
```c
int maxScore = 500;
int userScore = 423;
float percentage = (float) userScore / maxScore * 100.0;
printf("User's percentage is %.2f", percentage); // 84.60
```

## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.87
- **중복 검사 결과:** 신규 생성 (New discovery)

## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[C Tutorial]]
- **관련 개념:** [[C Files Write]], [[C Data Types Dec]], [[C Macros]]
- **참조 맥락:** 타입 변환 및 매크로 섹션 첫 챕터 — 전처리기와 매크로(Macros) 챕터로 이어짐.

## 📚 출처 (Sources)
- [S1] W3Schools — C Type Conversion — https://www.w3schools.com/c/c_type_conversion.php

## 📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "C Type Conversion" page (Astra wiki-curation, P-Reinforce v3.1 format).
