Why does sizeof(my_arr)[0] compile and equal sizeof(my_arr[0])?

sizeof is not a function. It’s a unary operator like ! or ~.

sizeof(my_arr)[0] parses as sizeof (my_arr)[0], which is just sizeof my_arr[0] with redundant parentheses.

This is just like !(my_arr)[0] parses as !(my_arr[0]).

In general, postfix operators have higher precedence than prefix operators in C. sizeof *a[i]++ parses as sizeof (*((a[i])++)) (the postfix operators [] and ++ are applied to a first, then the prefix operators * and sizeof).

(This is the expression version of sizeof. There’s also a type version, which takes a parenthesized type name: sizeof (TYPE). In that case the parens would be required and part of the sizeof syntax.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)