Files
2nd/10_Wiki/Dev/Topic_C/C_Arrays_Loop.md
T
Antigravity Agent 1cfd3bbb56 docs(10_Wiki): 위키 구조 정리 — 언어 튜토리얼 카테고리 폴더 제거 + 신규 자산 동기화
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고,
Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
2026-07-05 00:10:59 +09:00

3.5 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
c-arrays-loop C Array Loop Programming_Language draft conceptual
loop through array
adaptive loop length
C 배열 반복문
B 0.86 2026-07-04 2026-07-04
c
programming-language
w3schools
arrays
loops
https://www.w3schools.com/c/c_arrays_loop.php

C Array Loop

🎯 한 줄 통찰 (One-line insight)

A hardcoded loop bound (i < 4) silently breaks the moment the array's contents change size — the source explicitly flags this as "not ideal, since it will only work for arrays of a specified size" — while replacing it with sizeof(arr)/sizeof(arr[0]) makes the SAME loop automatically correct for an array of ANY length, turning a brittle magic number into a self-maintaining computation. [S1]

🧠 핵심 개념 (Core concepts)

  • Hardcoded loop bound (fragile)for (i = 0; i < 4; i++) only works correctly for exactly a 4-element array; adding/removing elements breaks it silently. [S1]
  • sizeof formula-driven bound (robust)int length = sizeof(arr) / sizeof(arr[0]); for (i = 0; i < length; i++) automatically adapts to the array's actual current size. [S1]
  • Standing rule — the chapter's own summary: "Always use the sizeof formula when looping through arrays." [S1]

📖 세부 내용 (Details)

  • Fragile hardcoded-bound loop: int myNumbers[] = {25, 50, 75, 100}; int i; for (i = 0; i < 4; i++) { printf("%d\n", myNumbers[i]); }. [S1]
  • Robust size-adaptive loop: int myNumbers[] = {25, 50, 75, 100}; int length = sizeof(myNumbers) / sizeof(myNumbers[0]); int i; for (i = 0; i < length; i++) { printf("%d\n", myNumbers[i]); }. [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

  • 하드코딩된 루프 경계의 취약성: 배열 원소 개수가 바뀌면 i < 4 같은 고정된 조건이 더 이상 맞지 않게 된다는 점이 "이상적이지 않다"고 명시적으로 지적되며, sizeof 공식을 항상 쓰라는 규칙으로 이어짐. [S1]

🛠️ 적용 사례 (Applied in summary)

현재 발견된 실제 적용 사례가 없습니다 — sizeof 기반 반복문이 이후 Arrays RealLife 챕터의 평균 계산·최솟값 찾기 예제에서 그대로 재사용된다. [S1]

💻 코드 패턴 (Code patterns)

A loop that automatically adapts to any array size using the sizeof formula (C):

int myNumbers[] = {25, 50, 75, 100};
int length = sizeof(myNumbers) / sizeof(myNumbers[0]);
int i;
for (i = 0; i < length; i++) {
  printf("%d\n", myNumbers[i]);
}

검증 상태 및 신뢰도

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

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-07-04: Initial draft synthesized from the W3Schools "C Array Loop" page (Astra wiki-curation, P-Reinforce v3.1 format).