1、指針可以爲NULL,但引用不可以
2、指針隨意更改,不會影響到原始數據。但引用是原始數據的別名,所以引用一旦更改,原始數據的指向也就更改了!
#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
int main() {
int a = 3;
int b = 4;
int&c = a;
c = b;
cout << a << " " << c << endl;
system("pause");
return 0;
}
這裏輸出的a=4,因爲c作爲a的別名,指向了b;