> For the complete documentation index, see [llms.txt](https://krjaeh0.gitbook.io/j-log/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://krjaeh0.gitbook.io/j-log/programming/cs-fundamentals/overviews/datastructuresalgorithms/array.md).

# array

## 배열이란?

* 개별 변수를 사용하는 방법은 동일한 타입(역할)의 변수가 많아지면 관리하기 어려워지는 단점이 있다.
* 동일한 타입에 동일한 역할을 수행하는 변수를 연속된 메모리 공간에 한번에 선언(정의)하는 것으로 단점을 해결할 수 있다.

```c
// 자료형 배열이름[배열크기];
int grade[10];
```

* 인덱스 참조는 0부터 시작
* 선언된 배열 크기보다 큰 인덱스 값으로 메모리에 접근하면 에러가 발생한다. (프로그램이 종료되지 않더라도 나중에 큰 문제가 될 수 있으므로 주의가 필요하다.)

### 배열 ADT

* 객체: <인덱스, 값> 쌍의 집합
* 연산:
  * create(size): size개의 요소를 저장할 수 있는 배열 생성
  * get(A, i): 배열 A의 i번째 요소를 반환
  * set(A, i, v): 배열 A의 i번째 위치에 값 v 저장

### 1차원 배열

```c
int list[6];
```

| list\[0] | list\[1]           | list\[2] | list\[3] | list\[4] | list\[5]                |
| -------- | ------------------ | -------- | -------- | -------- | ----------------------- |
| list     | list + sizeof(int) |          |          |          | list + 5 \* sizeof(int) |

### 2차원 배열

```c
int list[3][5];
```

|    | 0열           | 1열           | 2열           | 3열           | 4열           |
| -- | ------------ | ------------ | ------------ | ------------ | ------------ |
| 0행 | list\[0]\[0] | list\[0]\[1] | list\[0]\[2] | list\[0]\[3] | list\[0]\[4] |
| 1행 | list\[1]\[0] | list\[1]\[1] | list\[1]\[2] | list\[1]\[3] | list\[1]\[4] |
| 2행 | list\[2]\[0] | list\[2]\[1] | list\[2]\[2] | list\[2]\[3] | list\[2]\[4] |

## 배열의 응용

* 다항식 표현
* 행렬 표현(희소행렬)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://krjaeh0.gitbook.io/j-log/programming/cs-fundamentals/overviews/datastructuresalgorithms/array.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
