<소스>
1 : #include <stdio.h>
2 : void by_value(int a, int b, int c); //call by value : 값에 의한 호출
3 : void by_ref(int *a, int *b, int *c); //call by reference : 참조에 의한 호출
4 : void main()
5 : {
6 : int x =2, y = 4, z = 6;
7 : printf("\nBefore calling by_value(), x = %d, y = %d, z = %d.", x, y, z);
8 : by_value(x, y, z); //x, y, z는 지역변수 이기 때문에 main 내에서만 효과를 발휘합니다.
9 : printf("\nAfter calling by_value(), x = %d, y = %d, z = %d.", x, y, z);
10 : by_ref(&x, &y, &z); //하지만 이들의 주소값을 넘겨주면...
11 : printf("\nAfter calling by_ref(), x = %d, y = %d, z = %d.\n", x, y, z);
12 : }
13 : void by_value(int a, int b, int c){
14 : a = 0; //아무리 초기화를 해도 되지 않을 수밖에....
15 : b = 0;
16 : c = 0;
17 : }
18 : void by_ref(int *a, int *b, int *c){
19 : //그 주소값을 받아 그 주소 안의 값을 0으로 초기화 해주게 됩니다.
19 : *a = 0;
20 : *b = 0;
21 : *c = 0;
22 : }
<결과화면>
'Backend > C' 카테고리의 다른 글
함수 인수로 사용되는 포인터 (0) | 2012.04.12 |
---|---|
포인터(pointer)란 무엇인가? (0) | 2012.04.12 |
문자열의 길이를 계산하는 두 가지 방법 (0) | 2012.04.12 |
argc, argv를 이용한 간단한 사칙연산. (0) | 2012.04.12 |
strcpy()함수 (0) | 2012.04.12 |