Which of the * and [] links the strongest in C?

Possible duplicate:
C pointer to an array / array of pointer values

Does C have an int *thing[5]array of five pointers, each of which points to an integer, or a pointer to an array of five integers?

+5
source share
4 answers

[]trumps *per C priority table , which means you have an array of five int pointers.

+7
source

If in doubt, use parentheses - service programmers will be grateful to you (like you at 5 in the morning, when you finally find an error!)

+6
source

, ... ; cdecl, , :

cdecl> explain int *t[5];
declare t as array 5 of pointer to int
+4

, [], () *,

T *a[N];        -- a is an N-element array of pointer to T
T (*a)[N];      -- a is a pointer to an N-element array of T

T *f();         -- f is a function returning pointer to T
T (*f)();       -- f is a pointer to a function returning T

( , 5- ., B):

declarator:
  pointer-declarator
  direct-declarator

pointer-declarator:
  pointer direct-declarator

pointer:
  * type-qualifier-listopt
  * type-qualifier-listopt pointer

direct-declarator:
  simple-declarator
  ( declarator )
  function-declarator
  array-declarator

function-declarator:
  direct-declarator ( parameter-type-list )
  direct-declarator ( identifier-listopt )

array-declarator:
  direct-declarator [ constant-expressionopt ]
  direct-declarator [ array-qualifier-listopt array-size-expressionopt ] 
  direct-declarator [ array-qualifier-listopt * ]
0

All Articles