C++中指针的引用详解
指针(*)和引用(&),解引用(*)和取地点(&), 主要调查是在左面, 照旧在右面, 假如在左面是前者, 在右面是后者;
假如较量多, 则要当真调查, 譬如int*&, 就是指针的引用, 可以制止指针内部元素的复制;
尚有其他的一些形式, 见下面的例子;
代码:
/* * test.cpp * * Created on: 2013.11.12 * Author: Caroline */ /*eclipse cdt; gcc 4.7.1*/ #include <iostream> int main (void) { int i(10); int* j = &i; int i1(20); int*& k = j; //指针的引用, *k是*j的引用 *k = i1; //修改*k所指的内容, 则修改*j的内容; typedef int* pint; pint& k2 = j; int* k3 = &*j, k4 = 10; std::cout << "*k = " << *k <<std::endl; std::cout << "*j = " << *j <<std::endl; std::cout << "*k2 = " << *k2 << std::endl; std::cout << "*k3 = " << *k3 << std::endl; std::cout << "k4 = " << k4 << std::endl; return 0; }
作者:csdn博客 Spike_King