0

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

  • 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"

Any help/explanation will be appreciated.

2
  • 2
    Get cdecl and don't look back. Commented Jun 14, 2013 at 18:28
  • @CarlNorum definitely, you're right. :) Commented Jun 14, 2013 at 23:03

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

Comments

2
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.

Comments

1
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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.