我目前正在学习数据结构和算法课程,我的教授给了我们材料,其中包括接收指针值和指针/引用值的函数。
这些函数看起来像这样:
int function1(int a); // Pass by value
int function2(int &ref); // Pass by reference
int function3(int* ptr); // This will take in a pointer value
int function4(int*& ptr); // This will take in a pointer/reference value
Run Code Online (Sandbox Code Playgroud)
我了解按值传递和按引用传递之间的区别。我也尝试将后两个示例都实现为基本函数,但我不完全确定这两个参数与引用传递有何不同,或者它们之间有何不同。
有人可以解释这两个函数参数是如何工作的以及它们如何实际使用吗?