Files
2nd/10_Wiki/Topic_Programming/Topic_C/C_Pointers_Arithmetic.md
T
Antigravity Agent e9cbf23ab5 docs(10_Wiki): Dev 폴더 누락분 반영 — Topic_Programming으로 통합
이전 재구성 작업에서 Dev/ 폴더가 누락되었던 것을 반영.

- Dev/Topic_Programming(중첩 폴더, 78개)은 Dev 자체 최상위 폴더들
  (Architecture/Conventions/Engineering_Intelligence 등)과 완전 중복이라 제거.
- Dev 최상위 엔지니어링 지식 폴더(Architecture/Conventions/Engineering_Intelligence/
  Failure_Library/Generalized_Principles/Language/Pattern_Catalog/Platform_Guides/
  Subsystems, 77개)는 이미 Topic_Programming/Topic_Programming에 더 최신 버전이
  존재해 중복 제거(고유 콘텐츠 1개는 예외 처리하여 이동 보존).
- Dev의 W3Schools 언어 튜토리얼 폴더(Topic_C/CPP/CSS/CSharp/HOWTO/HTML/Java/
  JavaScript/PHP/Python/SQL/W3CSS, 1201개)는 전부 Topic_Programming 하위로 이동.
- 에이전트 운영 상태(.astra/docs)는 그대로 유지, 콘텐츠 폴더만 정리.
- Topic_Programming 최종 문서 수: 2784 → 3985.
2026-07-05 00:39:13 +09:00

4.7 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-pointers-arithmetic C Pointer Arithmetic Programming_Language draft conceptual
pointer increment
pointer subtraction
type-scaled pointer movement
C 포인터 연산
B 0.87 2026-07-04 2026-07-04
c
programming-language
w3schools
pointers
pointer-arithmetic
https://www.w3schools.com/c/c_pointers_arithmetic.php

C Pointer Arithmetic

🎯 한 줄 통찰 (One-line insight)

Adding 1 to a pointer never means "move forward by 1 byte" — it means "move forward by the SIZE of whatever type the pointer points to" — so from the same starting address, int* + 1 jumps 4 bytes while char* + 1 jumps only 1 byte, meaning pointer arithmetic is silently type-scaled, and mixing up pointer types is explicitly called out as a common mistake that lands you at the wrong memory location entirely. [S1]

🧠 핵심 개념 (Core concepts)

  • Pointer arithmetic — changing a pointer's VALUE to make it reference a different element, exploiting the fact that array elements sit contiguously in memory. [S1]
  • ++/--/+=/-= on pointers — move the pointer forward/backward by one (or N) elements, just like a loop counter. [S1]
  • Type-scaled movementp + 1 advances by sizeof(pointed-to type) bytes, not literally 1 byte; an int* moves 4 bytes per step while a char* moves 1 byte per step. [S1]
  • Pointer subtraction (distance) — subtracting two pointers INTO THE SAME ARRAY yields the number of ELEMENTS between them, not bytes; only valid when both pointers reference the same array. [S1]
  • Pointer-driven loop — looping by incrementing the pointer itself (p++) instead of indexing (myNumbers[i]) needs no separate index variable at all. [S1]

📖 세부 내용 (Details)

  • Accessing array elements via pointer offset: int myNumbers[4] = {25, 50, 75, 100}; int *p = myNumbers; printf("%d\n", *p); printf("%d\n", *(p + 1)); // 50. [S1]
  • Moving a pointer with increment/decrement/step: p++; // next element p--; // previous element p += 2; // jump 2 elements. [S1]
  • Pointer subtraction giving element count: int *start = &myNumbers[1]; int *end = &myNumbers[4]; printf("%ld\n", end - start); // 3 elements apart. [S1]
  • Type-dependent step size proven side by side: int *pi = myNumbers; // moves by sizeof(int), typically 4 bytes char *pc = letters; // moves by 1 byte. [S1]
  • Pointer-only loop (no index variable): int *p = myNumbers; for (int i = 0; i < 4; i++) { printf("%d\n", *p); p++; }. [S1]

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

  • 포인터 이동은 타입에 따라 크기가 다름: int는 한 칸 이동 시 보통 4바이트, char는 1바이트만 이동한다는 점이 동일한 시작 주소에서 직접 비교되어 확인되며, 타입을 혼동하면 잘못된 메모리 위치를 가리키게 된다고 경고됨. [S1]
  • 배열 경계를 벗어나는 이동 금지: 배열의 끝을 한 칸 넘어선 위치까지는 포인터 비교용으로만 안전하며, 그 값을 실제로 역참조해서는 안 된다는 점이 명시됨. [S1]

🛠️ 적용 사례 (Applied in summary)

현재 발견된 실제 적용 사례가 없습니다 — 인덱스 변수 없이 포인터 자체를 증가시키며 배열을 순회하는 방식이 메모리를 직접 다루는 실전 코드에서 흔히 쓰이는 패턴으로 소개됨. [S1]

💻 코드 패턴 (Code patterns)

Looping through an array by advancing the pointer itself, with no index variable (C):

int myNumbers[4] = {25, 50, 75, 100};
int *p = myNumbers;    // start of array
for (int i = 0; i < 4; i++) {
  printf("%d\n", *p);
  p++; // move to next element
}

검증 상태 및 신뢰도

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

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

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