# 4.6.    함수

함수(function), 서브루틴(subroutine), 루틴(routine), 메서드(method), 프로시저(procedure)는 소프트웨어에서 특정 동작을 수행하는 일정 코드 부분을 의미합니다.

함수는 대부분의 프로그래밍 언어에서 지원하는 기능으로, 하나의 큰 프로그램을 여러 부분으로 나누어 주기 때문에 같은 함수를 여러 상황에서 여러 차례 호출할 수 있으며 일부분을 수정하기 쉽다는 장점을 가집니다.

함수를 사용함으로써 얻는 장점은 다음과 같은 것들이 있습니다.

* &#x20;      하나의 큰 프로그램을 여러 부분으로 분리함으로써 [구조적 프로그래밍](https://ko.wikipedia.org/wiki/%EA%B5%AC%EC%A1%B0%EC%A0%81_%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D)이 가능합니다.
* &#x20;      같은 코드를 계속 쓰지 않음으로서 프로그램의 용량을 줄일 수 있고, 다른 부분이나 다른 프로그램에서 같은 코드를 사용할 수 있습니다.
* &#x20;      함수의 기능과 내부 구현을 분리하는 [캡슐화](https://ko.wikipedia.org/wiki/%EC%BA%A1%EC%8A%90%ED%99%94)가 이루어집니다.

#### 함수 호출의 순서

함수를 지원하는 일반적인 프로그래밍 언어에서는 다음과 같은 구조를 갖습니다.

1. 어떤 루틴에서 함수를 호출합니다. 이때 함수가 가지는 특정 변수에 값을 전달하기도 하며, 이 특정 변수를 매개변수(parameter)라고 하며 전달되는 값을 인자(argument)라고 부릅니다.
2. 함수가 호출되어 계산을 수행합니다.
3. 함수가 종료되고 실행 흐름이 원래의 루틴으로 돌아온다. 경우에 따라서는 함수가 계산하여 반환된 값(반환값, return value)을 원래의 루틴에서 사용하기도 합니다.


---

# Agent Instructions: 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:

```
GET https://sdc-james.gitbook.io/onebook/3./3.6..md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
