The below fails to compile:
typedef int arr[10];
int main(void) {
return sizeof arr;
}
sizeof.c:3: error: expected expression before ‘arr’
but if I change it to
sizeof(arr);
everything is fine. Why?
c++sizeof
The below fails to compile:
typedef int arr[10];
int main(void) {
return sizeof arr;
}
sizeof.c:3: error: expected expression before ‘arr’
but if I change it to
sizeof(arr);
everything is fine. Why?
Best Answer
According to 6.5.3, there are two forms for
sizeof
as the following:Since
arr
in your code is atype-name
, it has to be parenthesized.