为了账号安全,请及时绑定邮箱和手机立即绑定

“取消引用”指针是什么意思?

“取消引用”指针是什么意思?

C++ C
守着星空守着你 2019-06-06 14:49:21
“取消引用”指针是什么意思?请举例说明。
查看完整描述

3 回答

?
回首忆惘然

TA贡献1847条经验 获得超11个赞

删除指针意味着获取存储在指针指向的内存位置中的值。操作符*用于执行此操作,并称为取消引用运算符。

int a = 10;int* ptr = &a;printf("%d", *ptr); // With *ptr I'm dereferencing the pointer. 
                    // Which means, I am asking the value pointed at by the pointer.
                    // ptr is pointing to the location in memory of the variable a.
                    // In a's location, we have 10. So, dereferencing gives this value.
                    // Since we have indirect control over a's location, we can modify its content using the pointer. 
                    This is an indirect way to access a.

 *ptr = 20;         // Now a's content is no longer 10, and has been modified to 20.


查看完整回答
反对 回复 2019-06-06
?
汪汪一只猫

TA贡献1898条经验 获得超8个赞

指针是对值的“引用”。就像图书馆的电话号码是一本书的参考。电话号码正在物理上通过并检索那本书。

int a=4 ;int *pA = &a ;printf( "The REFERENCE/call number for the variable `a` is %p\n", pA ) ;// The * causes pA to DEREFERENCE...  
`a` via "callnumber" `pA`.printf( "%d\n", *pA ) ; // prints 4..

如果书不在那里,图书管理员就大声叫喊,关闭图书馆,几个人准备调查一个人找不到书的原因。


查看完整回答
反对 回复 2019-06-06
  • 3 回答
  • 0 关注
  • 1536 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信