Skip to content

Commit 3b06754

Browse files
author
고정완 (Can)
committed
[아이템 46] call by reference 에 관한 설명 보완
1 parent db4cebf commit 3b06754

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

chapter07/item46/item46.md

+41
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
# 아이템46. 스트림에서는 부작용 없는 함수를 사용하라
22

3+
## 파이로가 오해한 점 정리
4+
5+
### telescoping
6+
7+
- 헤드폰 밴드가 사람 머리 사이즈에 맞춰서 늘렸다 줄였다 할 수 있는 움직임을 telescoping이라고 표현
8+
- **telescoping argument list 패턴**: 매개변수가 더 많은 overloaded 함수를 정의할 때 매개변수의 순서를 바꾸지 않는 것
9+
10+
### Call by Reference
11+
12+
#### Reference vs Address
13+
14+
- **address**: value that corresponds to a place in memory
15+
- **reference**: name that refers to an existing object, rather than being it's own object.
16+
17+
자바는 기본적으로 **pass by value** 만을 언어적으로 허용한다. <br>
18+
따라서 자바에서 address value 를 pass 해서 참조할 수는 있어도, <br>
19+
reference 라는 개념은 자바에서 허용되지 않는다.
20+
21+
#### Reference 의 예시
22+
23+
아래의 c++ 코드에서 `&a``&b` 가 바로 reference 이다. <br>
24+
자바에서는 value 에 대한 직접적인 reference 를 언어적으로 지원하지 않는다. <br>
25+
기껏해야 value 를 객체로 감싸서, 객체의 address를 통해 객체 내부의 값을 변경할 수 있을 뿐이다.
26+
27+
```cpp
28+
void switch_by_ref(int &a, int &b) {
29+
int temp = a;
30+
a = b;
31+
b = temp;
32+
}
33+
34+
int main() {
35+
int a = 10;
36+
int b = 20;
37+
switch_by_ref(a, b); // a, b 의 값이 서로 바뀌어 있다.
38+
cout << "a : " << a << endl;
39+
cout << "b : " << b << endl;
40+
return 0;
41+
}
42+
```
43+
344
## 질의응답
445
546
### 질문1.

0 commit comments

Comments
 (0)