c++数组/指针声明问题

c++ array/pointer declarations issue

本文关键字:声明 问题 指针 数组 c++      更新时间:2023-10-16

我正在尝试解决c++中以下三个声明之间的差异。我附加了我的猜测:

  • const float *x[4] -常量浮点数数组指针的四元素数组
  • const float (*x)[4] -我在这里很困惑…和上面一样吗?
  • const float *(*x)[4] -与上面相同,但"在常量浮点数数组的数组上"

使用cdecl来了解声明,

  1. const float *x[4] -声明x为指向const float
  2. 的指针的数组4
  3. const float (*x)[4] -声明x为指向const float
  4. 数组4的指针
  5. const float *(*x)[4] -声明x为指向const float
  6. 指针的指向数组4的指针

来源:cdecl.org

const float *x[4] - 4-element array of pointers on arrays of constant floats

指向常量浮点数的四元素指针数组。

const float (*x)[4] - I'm confused here... is it the same as above?

指向四元素常量浮点数数组的指针。

const float *(*x)[4] - the same as above but "on arrays of arrays of constant floats"

指向常量浮点数指针的四元素数组。

const float *x[4]    -  An array of pointers to constant floats
const float (*x)[4]  -  A pointer to an constant float array with 4 elements
const float *(*x)[4] -  A pointer to an array of pointers to constant float