引用只是别名吗?为什么老师上课时说其值的又做了一份拷贝呢?
參考答案:这样写应该很清楚了吧。。。。
[Copy to clipboard]CODE:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int i = 80;
int *p = &i;
int &q = i;
cout << "i: " << i << endl;
cout << "&q: " << q << endl;
cout << "*p: " << *p << endl;
*p = 81;
cout << "&q: " << q << endl;
q = 82;
cout << "*p: " << *p << endl;
// the follows is a test:
// delete(p);
// cout << "Current &q: " << q << endl;
// cout << "Current i: " << i << endl;
return 0;
}