我目前正在学习数据结构和算法课程,我的教授提供了一些材料,其中包括接受指针值和指针/引用值的函数。
这些函数看起来像这样:
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
我理解 按值传递 和 按引用传递 的区别。我也尝试过将这两个例子实现为基本函数,但是我不确定这两个参数与按引用传递的区别以及它们彼此之间的区别。
有没有人能够解释一下这两个函数参数如何工作以及它们如何在实践中使用?