//正常的引用操作
#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 是傳遞數(shù)組內(nèi)存地址給函數(shù),函數(shù)可以通過arr[i]間接訪問數(shù)組里面的內(nèi)容進(jìn)行修改;簡(jiǎn)單說這里寫int arr[]也沒問題,沒區(qū)別都是指針
2019-03-06