int main(){
void swap(int,int);//參數爲整型變量
int i=3,j=4;
cout<<"i="<<i<<",j="<<j<<endl;
swap(i,j);//變量名
cout<<"i="<<i<<",j="<<j<<endl;
system("PAUSE");
return 0;
}
void swap(int a,int b){//形參爲整型變量
int temp;
temp=a;
a=b;
b=temp;
}
|
int main(){
void swap(int*,int*);//參數爲整型指針變量
int i=3,j=4;
cout<<"i="<<i<<",j="<<j<<endl;
swap(&i,&j);//變量地址
cout<<"i="<<i<<",j="<<j<<endl;
system("PAUSE");
return 0;
}
void swap(int *p1,int *p2){//形參爲整型指針變量
int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}
|
int main(){
void swap(int&,int&);//參數爲整型變量的引用
int i=3,j=4;
cout<<"i="<<i<<",j="<<j<<endl;
swap(i,j);//變量名
cout<<"i="<<i<<",j="<<j<<endl;
system("PAUSE");
return 0;
}
void swap(int &a,int &b){//形參爲引用類型
int temp;
temp=a;
a=b;
b=temp;
}
|