---
id: c-data-types-sizeof
title: "C The sizeof Operator"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["sizeof operator", "%zu", "size_t", "C sizeof 연산자"]
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", "sizeof", "memory"]
raw_sources: ["https://www.w3schools.com/c/c_data_types_sizeof.php"]
applied_in: []
github_commit: ""
---

# [[C The sizeof Operator]]

## 🎯 한 줄 통찰 (One-line insight)
`sizeof` doesn't return a plain `int` — it returns `size_t`, an unsigned integer type — so printing it with `%d` "might work on some computers" but is explicitly called out as unsafe/non-portable, meaning the correct specifier `%zu` isn't just a style preference but a genuine portability requirement for code that needs to run correctly across different systems. [S1]

## 🧠 핵심 개념 (Core concepts)
- **`sizeof`** — an operator (not a function, syntactically) that returns the number of bytes a type or variable occupies in memory. [S1]
- **`size_t`** — the unsigned integer type `sizeof` actually returns, requiring the `%zu` format specifier for safe/portable printing (not `%d`). [S1]
- **Practical memory-usage reasoning** — a 1000-element `char` array (1 byte each) occupies exactly 1000 bytes (1 KB), directly connecting type size to real memory footprint. [S1]
- **Motivation** — choosing the right data type for the right purpose saves memory and improves performance, especially in larger programs or memory-constrained environments. [S1]

## 📖 세부 내용 (Details)
- Basic usage on variables: `int myInt; printf("%zu\n", sizeof(myInt));`. [S1]
- Portability warning: using `%d` instead of `%zu` "might work on some computers" but `%zu` is "safer and more portable" since it matches `size_t`'s actual unsigned type. [S1]
- Memory-footprint reasoning: "if you have an array of 1000 char values, it will occupy 1000 bytes (1 KB) of memory" — 1 byte per char × 1000 elements. [S1]

## ⚖️ 모순 및 업데이트 (Contradictions & updates)
- **%d 대신 %zu를 써야 하는 이유**: sizeof가 반환하는 size_t는 부호 없는 정수형이라, %d로 출력하면 일부 컴퓨터에서는 우연히 동작할 수 있어도 이식성이 떨어진다는 점이 명확히 경고됨. [S1]

## 🛠️ 적용 사례 (Applied in summary)
현재 발견된 실제 적용 사례가 없습니다 — 1000개짜리 char 배열이 정확히 1KB를 차지한다는 계산이 메모리 제약 환경에서 타입 크기를 실전적으로 따져보는 대표 사례다. [S1]

## 💻 코드 패턴 (Code patterns)
Correctly printing sizeof() results using the %zu specifier, not %d (C):
```c
int myInt;
float myFloat;
printf("%zu\n", sizeof(myInt));
printf("%zu\n", sizeof(myFloat));
```

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

## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[C Tutorial]]
- **관련 개념:** [[C Data Types Extended]], [[C Data Types RealLife]], [[C Fixed Width Ints]]
- **참조 맥락:** sizeof 연산자 — 데이터 타입 실전 예제(Data Types RealLife) 챕터로 이어짐.

## 📚 출처 (Sources)
- [S1] W3Schools — C The sizeof Operator — https://www.w3schools.com/c/c_data_types_sizeof.php

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