Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of operations for dereference and bracket-ref in C

If I do *ptr[x], is that equivalent to *(ptr[x]), or (*ptr)[x]?

like image 699
Claudiu Avatar asked Aug 24 '10 01:08

Claudiu


2 Answers

*(ptr[x])

See the Wikipedia operator precedence table, or, for a more detailed table, this C/C++ specific table.

like image 144
Justin Ardini Avatar answered Nov 15 '22 17:11

Justin Ardini


In C, all postfix operators have higher precedence than prefix operators, and prefix operators have higher precedence than infix operators. So its *(ptr[x])

like image 20
Chris Dodd Avatar answered Nov 15 '22 19:11

Chris Dodd