Files
2nd/10_Wiki/Dev/Topic_CPP/CPP_Arrays_Omit.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

4.2 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
cpp-arrays-omit C++ Omit Array Size Programming_Language draft conceptual
fixed size vs dynamic size
vector introduction
C++ 배열 크기 생략
B 0.87 2026-07-04 2026-07-04
cpp
programming-language
w3schools
arrays
vectors
https://www.w3schools.com/cpp/cpp_arrays_omit.asp

CPP Omit Array Size

🎯 한 줄 통찰 (One-line insight)

This chapter reveals arrays' single biggest limitation and its solution in one place — a C++ array's size is FIXED forever once created (cars[3] = "Tesla"; on a 3-element array is an ERROR, not silent truncation), and the fix isn't a special array trick but an entirely different data structure, vector, whose push_back() grows the collection dynamically — meaning "I need to add elements later" is the signal to reach for vector instead of array from the very start of a design, not something to patch onto an array afterward. [S1]

🧠 핵심 개념 (Core concepts)

  • Omitting array size at declarationstring cars[] = {"Volvo", "BMW", "Ford"}; lets the compiler infer the size from the initializer list; equivalent to explicitly writing [3]. [S1]
  • Explicit size is "good practice" — reduces the chance of errors, even though omitting it works. [S1]
  • Omitting elements requires a known sizestring cars[5]; (size specified) can be filled in later index by index; string cars[]; (no size) causes a compile error ("array size missing"). [S1]
  • Fixed size — an array's size can NEVER change after creation; attempting to add a new index beyond its declared size is an error. [S1]
  • vector<type> — from <vector>, a RESIZABLE array; grows/shrinks dynamically via functions like push_back(). [S1]

📖 세부 내용 (Details)

  • Size-omitted declaration inferring 3 elements: string cars[] = {"Volvo", "BMW", "Ford"}; — equivalent to string cars[3] = {...};. [S1]
  • The fixed-size error case: string cars[3] = {"Volvo", "BMW", "Ford"}; cars[3] = "Tesla"; // error — no 4th slot exists. [S1]
  • The vector alternative that CAN grow: vector<string> cars = {"Volvo", "BMW", "Ford"}; cars.push_back("Tesla"); // now has 4 elements. [S1]

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

  • 배열의 고정 크기 한계와 벡터라는 해법: 배열은 생성 후 크기를 절대 바꿀 수 없어 4번째 요소를 추가하려 하면 에러가 발생하지만, 라이브러리의 vector 타입은 push_back()으로 동적으로 크기를 늘릴 수 있다는 점이 명시적으로 소개됨 — C 튜토리얼에는 없던 C++ 고유의 해법. [S1]

🛠️ 적용 사례 (Applied in summary)

현재 발견된 실제 적용 사례가 없습니다 — 요소를 나중에 추가/삭제해야 하는 상황이라면 배열 대신 벡터를 선택해야 한다는 판단 기준이 실전 설계 결정에서 핵심이다. [S1]

💻 코드 패턴 (Code patterns)

A vector growing dynamically where a fixed-size array would error (C++):

#include <vector>
vector<string> cars = {"Volvo", "BMW", "Ford"};
cars.push_back("Tesla"); // vector can grow; a fixed array cannot

검증 상태 및 신뢰도

  • 상태: 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++ Omit Array Size" page (Astra wiki-curation, P-Reinforce v3.1 format).