//正常的引用操作
#include <iostream>
using namespace std;
int main(void)
{
int x = 3;
//定義引用,y是x的引用
int &y = x;
//打印x和y的值
cout << x << endl;
cout << y << endl;
//修改y的值
y = 10;
//再次打印x和y的值
cout << x << endl;
cout << y << endl;
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
int x = 3;
//定義引用,y是x的引用
int &y = x;
//打印x和y的值
cout << x << endl;
cout << y << endl;
//修改y的值
y = 10;
//再次打印x和y的值
cout << x << endl;
cout << y << endl;
return 0;
}
最贊回答 / SmilarSouls
int *arr 是傳遞數組內存地址給函數,函數可以通過arr[i]間接訪問數組里面的內容進行修改;簡單說這里寫int arr[]也沒問題,沒區別都是指針
2019-03-06