DAY 11
0
Software Development

## call by value很佔空間？

call by value(傳值)，大家很常用。原理就是把值給指定的function使用

``````int fun(int D, int E, int F){
printf("fun：%d\n",&D);
printf("fun：%d\n",&E);
printf("fun：%d\n",&F);
}

int main(){
int A=0;
int B=0;
int C=0;
printf("main：%d\n",&A);
printf("main：%d\n",&B);
printf("main：%d\n",&C);
fun(A, B, C);
return 0;
}
``````

1)主程式先宣告A,B,C三個變數，並輸出其位址(10進位)
2)再把A,B,C三個變數的值，傳給fun中的D,E,F三個變數，再輸出其位址(10進位)

=====================分格線=====================

``````int fun(int &D, int &E, int &F){
printf("fun：%d\n",&D);
printf("fun：%d\n",&E);
printf("fun：%d\n",&F);
}

int main(){
int A;
int B;
int C;
printf("main：%d\n",&A);
printf("main：%d\n",&B);
printf("main：%d\n",&C);
fun(A, B, C);
}
``````

=====================分格線=====================

``````int fun(){
int D;
int E;
int F;
printf("fun：%d\n",&D);
printf("fun：%d\n",&E);
printf("fun：%d\n",&F);
}

int main(){
int A;
int B;
int C;
printf("main：%d\n",&A);
printf("main：%d\n",&B);
printf("main：%d\n",&C);
fun();
}
``````

=====================分格線=====================

``````int fun(int *D, int *E, int *F){
printf("fun：%d\n",&D);
printf("fun：%d\n",&E);
printf("fun：%d\n",&F);
}

int main(){
int A;
int B;
int C;
printf("main：%d\n",&A);
printf("main：%d\n",&B);
printf("main：%d\n",&C);
fun(&A, &B, &C);
}
``````

1)分別把A,B,C變數的位址，傳給D,E,F變數儲存
2)再分別印出各變數

=====================推論=====================

=====================心得=====================