引用,r为变量i的引用,引用类型为int:
<span style="white-space:pre"> </span>int i = 0; <span style="white-space:pre"> </span>int &r = i; <span style="white-space:pre"> </span>r = 100;
指针的引用,r为变量p的引用,引用的是一个指针,类型为int:
int i = 42; int *p; int *&r = p; r = &i; *r = 0; cout << "i = " << *r << endl;
时间: 2024-12-28 21:00:50