指針(*)和引用(&),解引用(*)和取地址(&), 主要觀察是在左面, 還是在右面, 如果在左面是前者, 在右面是後者;
如果比較多, 則要認真觀察, 譬如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