这是一个指向数组开头的指针的指针吗? [英] Is this a pointer to a pointer of the start of an array?

查看:41
本文介绍了这是一个指向数组开头的指针的指针吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在帮助某人处理一些代码.他有这个:

I've just been helping someone out with some code. He had this:

char dataArray[10];

然后想得到一个指向数组开头的指针.而不是使用:

Then wanted to get a pointer to the start of the array. Rather than use:

&dataArray[0]

或者只是

dataArray

他用过

&dataArray

他最终得到了一个指向那里的指针的指针吗?我不确定 &dataArray 会给他什么.

Did he end up with a pointer to a pointer there? I'm not sure what &dataArray would give him.

推荐答案

  • &dataArray[0]char * 类型.这是一个指向 char 的指针.
  • dataArraychar[10]
  • 类型
  • &dataArray 的类型为 char (*)[10].这是一个指向数组的指针.
    • &dataArray[0] is of type char *. That is a pointer to char.
    • dataArray is of type char[10]
    • &dataArray will be of type char (*)[10]. That is a pointer-to-array.
    • 除此之外,将是相同的,即它们指向相同的地址但它们的类型不需要兼容.

      Apart from that, the value will be same, i.e., they point to the same address but their types need not be compatible.

      这里没有一个是指针到指针.它们只是不同类型的指针.

      None of them is a pointer-to-pointer here. They are just pointer with different types.

      注意:由于数组的衰减特性,char [100] 会衰减为char *,例如作为函数的参数传递时.

      Note: Because the array decaying property, char [100] will decay to a char *, for example, when passed as an agument of a function.

      这篇关于这是一个指向数组开头的指针的指针吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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