为什么?(当),我需要的sizeof后用括号? [英] Why (and when) do I need to use parentheses after sizeof?
本文介绍了为什么?(当),我需要的sizeof后用括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下无法编译:
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?
推荐答案
据6.5.3,有两种形式为的sizeof
如下:
According to 6.5.3, there are two forms for sizeof
as the following:
sizeof unary-expression
sizeof ( type-name )
由于改编
在code是键入名称
,它必须要加上括号。
Since arr
in your code is a type-name
, it has to be parenthesized.
这篇关于为什么?(当),我需要的sizeof后用括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文