Why does decay to pointer for array argument appear not to apply to sizeof()?

后端 未结 2 1695
旧时难觅i
旧时难觅i 2020-12-20 16:31

I read a question earlier that was closed due to being an exact duplicate of this

When a function has a specific-size array parameter, why is it replaced with a poin

2条回答
  •  天涯浪人
    2020-12-20 17:04

    sizeof is an operator, not a function. It's a specific one at that, too. The parentheses aren't even necessary if it's an expression:

    int a;
    sizeof (int); //needed because `int` is a type
    sizeof a; //optional because `a` is an expression
    sizeof (a); //^ also works 
    

    As you can see, it's on this chart of precedence as well. It's also one of the non-overloadable operators.

提交回复
热议问题