한 호
함
함
한 호
한포
함
함 ?
한포
함
함 ?
▶ 한 호(Call by Value)
C .
호 함 형 .
함 호하 호 함 형 해 하 .
한 호 하 .
호 함 형 .
함 호하 호 함 형 해 하 .
한 호 하 .
▶ 한 호 ( Call by Reference )
한 호 함 하 형 .
( 형 하 행 )
한 호(call by reference, call by address, call by location) 키
환 하 .
( 형 하 행 )
한 호(call by reference, call by address, call by location) 키
환 하 .
함 하 환하 C++ 함
main()함 할 main() main() 함
.
함 한 하..
main()함 할 main() main() 함
.
함 한 하..
함
1) 함
,,호 히 Compiler 해 object file 할 Pro
gramming .
2) 크 함
#define 해 함.
3) inline함
크 함 compiler 해 함 한
합.
1) 함
,,호 히 Compiler 해 object file 할 Pro
gramming .
2) 크 함
#define 해 함.
3) inline함
크 함 compiler 해 함 한
합.
함
1) 한
함 함 .
2) 한
하 템 태 할 .
1) 한
함 함 .
- 한 호(Call by value)
- 포 한 호(Call by pointer reference)
- 한 호(Call by reference)
하 2) 한
하 템 태 할 .
함 , , 호 해 ,
#include
#include
void main()
{
{
double power(double base, int exponent); // 함 (형)
double base,result;
int exponent;
cout << "밑수 및 지수를 입력하시오\n";
while (cin >> base >> exponent)
{
} double base,result;
int exponent;
cout << "밑수 및 지수를 입력하시오\n";
while (cin >> base >> exponent)
{
result = power(base, exponent); // 함 호
cout << "밑수("<< base <<")" << "지수("<< exponent <<")" << "결과 :"<< result << endl;
} cout << "밑수("<< base <<")" << "지수("<< exponent <<")" << "결과 :"<< result << endl;
double power (double x, int y) // 함
{
하 power 함 하 double base, int exponent 한. power()
함 형 함형 함 해 함,환형, 형 .
파 할 . 함 형
.
{
double ans="x";
for (int i=1;i < y;i++)
}for (int i=1;i < y;i++)
ans*="x";
return ans; - power(double x, int y) 표 할 ...? -
- 함 형 . -
하 power 함 하 double base, int exponent 한. power()
함 형 함형 함 해 함,환형, 형 .
파 할 . 함 형
.
해 .
함 main()함
포함하 합. 해 함 하
함 합.
함 main()함
포함하 합. 해 함 하
함 합.
.
#include
#include
void mytest(); // 함형
{
int x=1,y=2; //
void main(){
cout << "x="<< x <<" \n"; cout << "y="<< y <<" \n"; mytest(); // 함수선언
cout << "x="<< x <<" \n"; cout << "y="<< y <<" \n";
} cout << "x="<< x <<" \n"; cout << "y="<< y <<" \n";
void mytest() // 함
{
{
int x="3;" //
cout << "this x="<< x <<" \n"; cout << "this y="<< y <<" \n";
}cout << "this x="<< x <<" \n"; cout << "this y="<< y <<" \n";
.
x=1
y=2
this x=3
this y=2
x=1
y=2
함 mytest 한 x 3 this x=3
해 할 C++
함 하 함
. 힘 , 하
.
x=1
y=2
this x=3
this y=2
x=1
y=2
함 mytest 한 x 3 this x=3
해 할 C++
함 하 함
. 힘 , 하
.
함 .
한 호(Call by value )
: 하 호 함 해 향
void main()
{
한 호(Call by value )
: 하 호 함 해 향
.
#include <iostream.h>void main()
{
void test(int, int); // 함
int a = 10, b = 20;
test(a,b); // 함 호
cout << "a=" << a <<" " << "b=" << b << endl;
}int a = 10, b = 20;
test(a,b); // 함 호
cout << "a=" << a <<" " << "b=" << b << endl;
void test(int x, int y) // 함
{
{
int temp;
temp = x;
x = y;
y = temp;
}temp = x;
x = y;
y = temp;
a=10 b=20 x y 20, 10.
호함 해 하 .
호함 해 하 .
포 한 호(Call by point reference)
: 하 형 포 .
: 하 형 포 .
#include <iostream.h>
void main()
{
void main()
{
void test(int*, int*); // 함
int a = 10, b = 20;
test(&a,&b); // 함 호, ab
cout << "a=" << a <<" " << "b=" << b << endl;
}int a = 10, b = 20;
test(&a,&b); // 함 호, ab
cout << "a=" << a <<" " << "b=" << b << endl;
void test(int *x, int *y) // 함
{
{
int temp;
temp = *x;
temp = *x;
- x = *y;
- y = temp;
a=20 b=10 x a y b .
한 호(Call by reference)
: 형 하 하 함호 형 형
void main()
{
: 형 하 하 함호 형 형
화 함 하 할 .
#include <iostream.h>void main()
{
void test(int&, int&); // 함
int a = 10, b = 20;
test(a,b); // 함 호, 형
cout << "a=" << a <<" " // 참조형이 실매개 변수로 초기화 << "b=" << b << endl;
}int a = 10, b = 20;
test(a,b); // 함 호, 형
cout << "a=" << a <<" " // 참조형이 실매개 변수로 초기화 << "b=" << b << endl;
void test(int &x, int &y) // 함
{
{
int temp;
temp = x;
x = y;
y = temp;
}temp = x;
x = y;
y = temp;
a=20 b=20 함 하 하 .