ducin
ducin

Reputation: 26477

c++ array/pointer declarations issue

I'm trying to solve the difference between three following declarations in c++. I appended my guesses:

Any help/explanation will be appreciated.

Upvotes: 0

Views: 107

Answers (3)

VoidPointer
VoidPointer

Reputation: 3107

Use cdecl to know declarations,

  1. const float *x[4] - Declare x as array 4 of pointer to const float
  2. const float (*x)[4] - Declare x as pointer to array 4 of const float
  3. const float *(*x)[4] - Declare x as pointer to array 4 of pointer to const float

Source : cdecl.org

Upvotes: 4

Deepu
Deepu

Reputation: 7610

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 

Upvotes: 1

kotlomoy
kotlomoy

Reputation: 1430

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

4-element array of pointers to constant floats.

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

Pointer to 4-element array of constant floats.

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

Pointer to 4-element array of pointers to constant floats.

Upvotes: 2

Related Questions