c - C 中的指针 : why is the * needed in *address_of_x = &x when getting the address of x?

标签 c pointers syntax

假设我们有以下代码,它接受x,在其中存储值4,然后将x的地址存储在一个指针变量:

int x = 4;
int *address_of_x = &x;

int *address_of_x 中的* 有什么用? 我了解 * 用于取消引用指针 - 它需要一个地址并告诉您存储在那里的内容。但是如果一个地址被存储了,那么我们要解引用什么呢?或者我们根本没有取消引用任何东西?为什么不写成:

int address_of_x = &x;

最佳答案

int *address_of_x = &x; 中的

* 未取消引用 @Eugene Sh .
它是类型声明的一部分:pointer to int .

int x = 4;
int *address_of_x = &x;

一样
int x = 4;          // declare x as int
int *address_of_x;  // declare address_of_x as pointer to int
address_of_x = &x;  // Assign the address of x to address_of_x

Why isn't it written as: int address_of_x = &x;

&x 不是 int&x 是一个int *,一个指针(或地址)。指针不是整数。

关于c - C 中的指针 : why is the * needed in *address_of_x = &x when getting the address of x?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47437772/

相关文章:

c++ - 如何知道某个指针是否已在其他地方释放

python - Python 3 变量名接受哪些 Unicode 符号?

eclipse - 语法检查不适用于 Perl Eclipse 插件 (EPIC) 中的模块 (*.pm)

c - do While 循环不适用于 C 中的字符串比较

c++ - 在python脚本中加载.so文件时出现 undefined symbol 错误

c - C 指针表示法中的这些数组发生了什么?

javascript - "If""else"语句有语法错误

c# - P/Invoke - 结构参数的简单添加

c - 使用 pdcurses 显示重音字符

c - 移动指针并重新分配,C