c++的“ & ”
& 对参数的修改结果会带回来
举个🌰:
#include <iostream>
using namespace std;
void test(int &x){
x = 1023;
printf("test内部函数x=%d\n",x);
}
int main()
{
int x = 1;
printf("BEFROE CALL test内部函数x=%d\n",x);
test(x);
printf("AFTER CALL test内部函数x=%d\n",x);
return 0;
}
结果:
BEFROE CALL test内部函数x=1
test内部函数x=1023
AFTER CALL test内部函数x=1023