引用传递也可以称为指针传递吗?

标签 c function pointers

我目前正在阅读有关将参数传递给 C 函数的方法。在阅读时,我开始知道在 C 中有两种方法可以传递参数,即按值传递和按引用传递。 然后我又读到我们也可以将指向变量的指针作为参数传递。

The beginnersbook website this method is mentioned as pass by reference.

In this example, we are passing a pointer to a function. When we pass a pointer as an argument instead of a variable then the address of the variable is passed instead of the value. So any change made by the function using the pointer is permanently made at the address of passed variable. This technique is known as call by reference in C.

我知道当我们需要更改或访问原始变量时,我们可以使用 & 运算符传递一个指针变量或变量的地址。我想知道这种指针传递是否也可以称为引用传递。 指针传递也是引用传递的方法吗?

最佳答案

从技术上讲,C 中函数的所有 参数都是按值传递的。与 C++ 不同,该语言不支持真正的引用。

通过引用传递可以在 C 中通过传递(按值)您要修改的变量的地址来模拟,然后取消引用该地址以修改指向的值。然而,这不是真正的引用传递。

关于引用传递也可以称为指针传递吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65494174/

相关文章:

c - 使用 -std=c99 编译时,我需要使用 -pedantic 还是 -ansi?

c - 如何在 NetMQ 中使用 PollTimeout?

c - 在c中的二叉树中搜索字符串

php - 许多可选参数

python - 在 Python 函数中灵活拆分输入字符串

c - free()失败

函数可以返回字符串作为其输出吗?

c - 在不动态分配内存的情况下在C中复制任意类型

objective-c - Swift转换C的uint64_t与使用自己的UInt64类型不同

在 C 中将 1 个指针数组复制到第 2 个指针数组