C指针,指向:* PTR VS&放大器; PTR VS PTR [英] C Pointers: *ptr vs &ptr vs ptr

查看:149
本文介绍了C指针,指向:* PTR VS&放大器; PTR VS PTR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设 * PTR 指向一个变量。这是什么 * PTR &放大器; PTR PTR 各是什么意思?

Suppose *ptr points to a variable. What does *ptr, &ptr, and ptr each mean?

很多时候,我让他们之间的混淆。不要介意任何人的语句之间明确并给出一些具体的例子?

Many times, I get confused between them. Do anyone mind clarifying between those statements and give some concrete examples?

推荐答案

参加一个函数下列变量。

Take the following variables in a function.

int i = 0;
int* ptr = &i;

在功能,内存布局可能看起来是这样的:

In the function, the memory layout could look something like:

对应内存 I

+---+---+---+---+
|       0       |
+---+---+---+---+
^
|
Address of i

对应内存 PTR

+---+---+---+---+
| address of i  |
+---+---+---+---+
^
|
Address of ptr

在上面的场景中,

*ptr == i == 0
ptr == address of i == address of memory location where the vale of i is stored
&ptr == address of ptr == address of memory location where the value of ptr is stored.

希望是有道理的。

Hope that makes sense.

这篇关于C指针,指向:* PTR VS&放大器; PTR VS PTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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