void swap1(int& x, int& y){
int temp;
temp = y;
y = x;
x = temp;
}
C++引用作为参数传递,直接传入地址,不再开辟新的复制空间,c语言中没有
int main()
{
int x, y;
x = 10, y = 103;
// swap(&x, &y);
//
swap1(x,y);
cout<<"*x: "<<x<<"*y: "<<y<<endl;
cout << "Hello world!" << endl;
return 0;
}
C语言
void swap(int* x, int* y){
int temp;
temp = *y;
*y = *x;
*x = temp;
}
int main()
{
int x, y;
x = 10, y = 103;
swap(&x, &y);//一个int变量,加上了取地址符号就变成了指针
cout<<"*x: "<<x<<"*y: "<<y<<endl;
cout << "Hello world!" << endl;
return 0;
}
指针数组数组指针到底是什么东西
卧槽,可以直接以数组的形式传递