繁体   English   中英

价值传递中的困惑vrs参考/指针传递

[英]Confusion in pass by value vrs pass by reference/pointer

申报后

 void insert_LL(Node *head, int data);

调用时,头指针的副本到达函数,因此,如果在头处添加节点,则头的值将更改。 但是,由于我们具有head的本地副本,因此实际的header指针不会更改。 所以我们声明如下

 void insert_LL(Node **head, int data);

我的问题:

  1. 以上解释正确吗?

  2. 如果是,则意味着在C语言中,它始终是值传递(与函数中的指针副本相同),与Java中相同。 我对么?

  3. 如果是,那么如何通过引用/指针进入图像?

1-是

2-是

3- In C, Pass-by-reference is simulated by passing the address of a variable (a pointer) and dereferencing that address within the function to read or write the actual variable. This is referred as "C style pass-by-reference.". In C, Pass-by-reference is simulated by passing the address of a variable (a pointer) and dereferencing that address within the function to read or write the actual variable. This is referred as "C style pass-by-reference.".

按引用传递不是C中要使用的术语。指针变量的地址值被传递。 编译器使用对变量的引用进行存储,并为变量保留的存储位置指定名称。

引用和指针之间的主要区别在于,“指针”可以采用任何地址值,除非将其设置为“ const”。 而当您通过引用时,您就不能。

C ++中的指针变量和引用变量之间有什么区别?

该线程将完成所有需要的操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM