void f1(t a);
void f2(t &a);
int main(){
t a;
f1(a);
f2(&a);
f1(&a);
f2(a);
}
有人能详细解释一下Main中的四个函数调用有什么区别吗?
void f1(t a);
void f2(t &a);
int main(){
t a; //create a variable of type t;
f1(a);//pass the value of a to the function f1
f2(&a);//pass the address of a to the function f2 but, this function has a reference as a parameter so it shouldn't compile, you should pass the variable f2(a)
f1(&a); // pass the address of a to the function f1, so f1 should contain a pointer as a parameter, but that's not the case, so it won't compile
f2(a); //passing by reference to the function f2
}
请登录https://www.onlinegdb.com/