e9cbf23ab5
이전 재구성 작업에서 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.
4.2 KiB
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 |
|
B | 0.87 | 2026-07-04 | 2026-07-04 |
|
|
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 likepush_back(). [S1]
📖 세부 내용 (Details)
- Size-omitted declaration inferring 3 elements:
string cars[] = {"Volvo", "BMW", "Ford"};— equivalent tostring 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)
- 상위/루트: 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).