引用最大的价值是避免复制
#include <iostream> using namespace std; void method2(int& param) { param = param + 1; cout << "method2 inner:" << param << endl; //method2 inner:2 } void method1(int param) { param = param + 1; cout << "method1 inner:" << param << endl; //method1 inner:2 } int main() { int a { 1 }; method1(a); cout << "main:" << a << endl; //main:1 method2(a); cout << "main:" << a << endl; //main:2 char c = getchar(); return 0; }
标签:std,method2,c++,param,引用,include From: https://www.cnblogs.com/angdh/p/17719724.html