Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which of * and [] bind strongest in C? [duplicate]

Tags:

c

syntax

Possible Duplicate:
C pointer to array/array of pointers disambiguation

In C, is int *thing[5] an array of five pointers, each pointing to an integer, or a pointer to an array of five integers?

like image 655
me_and Avatar asked Jun 24 '10 15:06

me_and


3 Answers

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

like image 63
Amardeep AC9MF Avatar answered Oct 27 '22 15:10

Amardeep AC9MF


If in doubt use parenthesis - the maintenance programmers will thank you (as will you at 5am when you finally find the bug!)

like image 22
Martin Beckett Avatar answered Oct 27 '22 15:10

Martin Beckett


Maybe is a duplicate... It is an array of five pointers to integer; the program cdecl cited in a similar question can be useful for newbie:

cdecl> explain int *t[5];
declare t as array 5 of pointer to int
like image 4
ShinTakezou Avatar answered Oct 27 '22 14:10

ShinTakezou