c ++中的指针传递值/引用 [英] Pointers in c++ pass by value/reference

查看:133
本文介绍了c ++中的指针传递值/引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像简单变量,指针变量也可以用作函数中的Value参数或Reference参数.....但由于使用指针变量2保存内存位置或内存位置的内容,那么什么更多的差异会如果指针变量被用作Value或者参考参数?

like simple variables ,the pointer variables can also be used as a Value parameter or Reference parameter in functions..... but as the pointer variables are used 2 hold memory location or content of memory location then what more difference will it make if the pointer variable is used either as Value or as Reference parameter????

推荐答案

如果函数A传递指针P通过参考另一个函数B,则B可以使P指向存储器中的不同位置,并且A将看到该改变。另一方面,如果A将P乘以值,则B只能改变P指向的存储器的内容。 A将看到对该存储器的改变,但是当B返回时,P不会指向存储器中的不同的点。

If function A passes a pointer P by reference to another function B, then B can make P point to a different location in memory, and A will see that change. If, on the other hand, A passes P by value, then B can only change the contents of the memory that P points to. A will see changes to that memory, but P will never point to a different spot in memory when B returns.

这篇关于c ++中的指针传递值/引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆