In C, what this declaration means: int * (* table ()) [30];

int *(*table())[30];

I can not find a solution anywhere. What is * table (), can it be a function or an array?

Could you tell me what this means?

+4
source share
5 answers

You can decode this from the inside:

int *(*table())[30];

Inner binding table(), which is a function with undefined arguments. The next level *table(), therefore, tablereturns a pointer to something. The next level (*table())[30], so it returns a pointer to an array 30 lines long. The next level *(table())[30], so it returns a pointer to an array of 30 lines long pointers to something. At the last level, a type specifier is added int *(*table())[30].

, table - ( ), 30 int.

+5

, , , . say f is table(), , , t - int*.

:

t(*f)[30];

, , 30 t.

f, , 30 t:

t(*table())[30];

t, , , 30 int:

int*(*table())[30];
+3

:

int *(*table())[30];

, "table - , 30 int".

, C. .

:

:

  • . $typename.
  • - , , [] () *. $identifier.

: $identifier - ... $typename.

  1. "$ identifier (n)".

  2. , [...] (...), . [...] - (, ) , "array (of...)"; (...) - (, ) , " " " (...)".

  3. , , . , $typename, , (*, " (-) " ) . , $typename, .

    : , , , .

,

:

int *(*table())[30];

:

  • $typename = "int"
  • $identifier = "table";
  • "$ identifier (n)": "table (n)" ${typename} *(*${declaration}())[30];

  • : "... " ${typename} *(* ${declaration} )[30];

  • : - )
  • : "... " ${typename} * ${declaration} [30];
  • : "... 30" ${typename} * ${declaration};
  • : - ; ${typename} * ${declaration}
  • : "... " ${typename} ${declaration}
  • : .
  • : "int"

, :

table - (n) , () 30 () int

, (), , "":

table - , 30 int.

0

/.

enter image description here

:

1) table - .

2) table() .

3) , table(), 30.

4) , .. .

: " / "

0

- , 30 . / , http://cdecl.org/, .

, . , . , , , , , Foo. , void, , :

typedef int *(*Table)[30];

Table FooTable(void);
0

All Articles