Why is sizeof considered an operator and not a function?
What property is necessary to qualify as an operator?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because the C standard says so, and it gets the only vote.
As consequences:
sizeof (int), instead of an object expression.int a; printf("%d\n", sizeof a);is perfectly fine. They’re often seen, firstly because they’re needed as part of a type cast expression, and secondly because sizeof has very high precedence, sosizeof a + bisn’t the same assizeof (a+b). But they aren’t part of the invocation of sizeof, they’re part of the operand.sizeof a++does not modify a).A function would differ on all those points. There are probably other differences between a function and a unary operator, but I think that’s enough to show why sizeof could not be a function even if there was a reason to want it to be.