• 本质:引用的本质在C++内部实现是一个指针常量 ```cpp

    include

using namespace std;

// 发现是引用,转换为int const ref = &a; void func(int & ref) { ref = 100; // ref是引用,转换为 ref = 100 } int main() { int a = 10;

  1. // 自动转换为int * const ref = &a; 指针常量是指针指向不可改,也说明为什么引用不可更改
  2. int& ref = a;
  3. ref = 20;
  4. cout << "a:" << a << endl;
  5. cout << "ref: " << ref << endl;
  6. func(a);
  7. system("pause");
  8. return 0;

} ```

结论:C++推荐引用技术,因为语法方便,引用本质是指针常量,但是所有的指针操作编译器都帮我们做了