C++: pointer reference
整理自:Thinking in C++
pointer 也可以有 reference,注意语法:
#include <iostream>
using namespace std;
void increment(int*& i) { // i is a reference of int*
i++;
}
int main() {
int a = 5;
int* i = &a;
cout << "i = " << i << endl;
increment(i);
cout << "i = " << i << endl;
}
// output:
/*
i = 0x22fe3c
i = 0x22fe40
*/
Comments