값
개 값
값
개 값
값
개
개 값 경
?
▶ 값 (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) 개
간 .
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 결국 개 .