---
id: cpp-arrays-omit
title: "C++ Omit Array Size"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["fixed size vs dynamic size", "vector introduction", "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: ["cpp", "programming-language", "w3schools", "arrays", "vectors"]
raw_sources: ["https://www.w3schools.com/cpp/cpp_arrays_omit.asp"]
applied_in: []
github_commit: ""
---

# [[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 declaration** — `string 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 size** — `string 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> 라이브러리의 vector 타입은 push_back()으로 동적으로 크기를 늘릴 수 있다는 점이 명시적으로 소개됨 — C 튜토리얼에는 없던 C++ 고유의 해법. [S1]

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

## 💻 코드 패턴 (Code patterns)
A vector growing dynamically where a fixed-size array would error (C++):
```cpp
#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)
- **상위/루트:** [[C++ Tutorial]]
- **관련 개념:** [[CPP Arrays Multi]], [[CPP Vectors]], [[CPP Arrays RealLife]]
- **참조 맥락:** 배열 크기 생략과 벡터 소개 — 배열 실전 예제(Arrays RealLife) 챕터로 이어짐, 벡터(Vectors) 챕터와 직접 연결.

## 📚 출처 (Sources)
- [S1] W3Schools — C++ Omit Array Size — https://www.w3schools.com/cpp/cpp_arrays_omit.asp

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