首页 >> 大全

iterator指针回到0_回到基础与指针

2023-11-30 大全 28 作者:考证青年

现在让我们瞄准指针 (Now Let’s the )

A is a , used to store the of .

指针是一个变量,用于存储另一个变量的内存地址。

The the of the first byte of a , as we know the size of a , the rest of the bytes are easy to .

指针存储变量的第一个字节的地址,因为我们知道变量的大小,其余字节很容易计算。

在C中声明指针 ( in C)

* is used to . The looks like this-

*符号用于声明指针。 声明看起来像这样-

int *p; and we like this — int v;

_指针的返回值_指针作为返回值有什么用

int *p; 并且我们这样声明变量— int v;

We can now say that p is a ‘ to int’, of the type int. It will store the of .

由于类型int ,我们现在可以说p是“指向int的指针” 。 它将存储整数变量的地址。

All the are of the same size they just store a , which does not for a . , data types .

所有指针的大小相同,因为它们仅存储一个内存地址,对于计算机而言,该地址不会更改。 但是,不同的数据类型需要不同的指针声明。

char * character;
double * number;
float * balance;

This was just the . Right now they do not store any value. To do that, we must them with the of to store. In C, the & AKA ‘-of ’ is used to get the of a .

这只是宣言。 目前,它们不存储任何值。 为此,我们必须为他们提供另一个要存储的变量的地址。 在C语言中,“&”符号& AKA“运算符的地址”用于获取变量的地址。

int a = 1000; // a stores the value 1000
int *p = &a; // p stores the memory address of a. NOT 1000
// Another Wayint a = 1000;
int *p;
p = &a; // Notice * is not used again. We only use it while declaring.

取消引用指针 ( )

Once a is , the next step is to use it. We need to refer to the value it to, known as the of the . This is known as the . To do this, we use the *.

声明指针后,下一步就是使用它。 我们需要引用它指向的值,称为指针的目标。 这称为取消引用指针。 为此,我们使用符号* 。

int * ptr;  // declaring a pointer to int
int a = 6; // a stores the value 6
ptr = &a; // p stores the memory address of a. NOT 6
printf("%d", *ptr); //prints 6. Astrix is used to dereference the pointer

空指针 (Null )

A null is a with a value 0. 0 is the only value you can to a , will give an error. A null is a you can use to a later. Here’s how to set null —

空指针是值为0的特殊指针。0是可以分配给指针的唯一整数值​​,任意值都会产生错误。 空指针是一个占位符,以后可以用来初始化指针。 这是设置空指针的方法-

int *p = 0; //Works fine
int *z = 100; //Error
int a = 420;p = &a; //Works fine. Now P stores the address of a

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了