3

What does the following declaration mean?

unsigned char (*pArray[10][10]);
Amateur
  • 31
  • 5

3 Answers3

4

Declaration

unsigned char (*pArray[10][10]);

is exactly equivalent to

unsigned char *pArray[10][10];

The parentheses are entirely redundant and have no effect at all. This is a 2D 10x10 array of unsigned char * pointers.

AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765
  • 4
    "entirely redundant and have no effect at all" - isn't that phrasing a bit redundant? :) – thedayturns Apr 17 '11 at 18:45
  • 1
    Well, every time I think about redundancy I always come up with such excessive phrasing all the time without a single exception :) – AnT stands with Russia Apr 17 '11 at 18:47
  • At least AndreyT is not an Oxymoron.haha – Sadique Apr 17 '11 at 18:49
  • I can weasel my way out of this: in case of `int ((*p))[10]` braces are redundant but do have effect (i.e. the extra pair of braces is redundant, but in general braces matter), while in case or `int ((p))` the braces are both redundant and have no effect :) – AnT stands with Russia Apr 17 '11 at 18:52
3

cdecl says:

declare pArray as array 10 of array 10 of pointer to unsigned char

Basically what you did was to declare a 2-D Array of pointers.

See this question:

Equivalent C declarations

Now try to parse this:

int **(*f)(int**,int**(*)(int **,int **));

[ In your mind of course ]

Community
  • 1
  • 1
Sadique
  • 22,572
  • 7
  • 65
  • 91
  • That's simple... pointer to function that returns an `int**`, and takes two arguments, an `int**` and a pointer to a function that takes two `int**` as arguments and return another `int**`... Adding a few arrays there would make it a little more interesting... `int *(*p( int** ))[10]`, as one of the function arguments... – David Rodríguez - dribeas Apr 17 '11 at 19:27
  • 2
    @David::Hmm.. how about this: `int **(*f)(int**,int**([5])(int **,int **[5]))[5]();` – Sadique Apr 17 '11 at 22:35
0

www.cdecl.org says:

declare pArray as array 10 of array 10 of pointer to unsigned char

j0k
  • 22,600
  • 28
  • 79
  • 90
Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171