Sizeof is both a keyword and an operator, but not a function !, Sizeof Operator
Is sizeof a keyword?
Sizeof is a keywordThis is beyond doubt. You cannot define sizeof as any identifier. View the instructions in the C language standard documentation:
Is sizeof an operator?
C language,Sizeof is an operator)And is the only operator that appears in the form of words. It is used to calculate the number of bytes required to store a certain amount. Its combination is from right to left. View the instructions in the C language standard documentation:
Is sizeof a function?
Sizeof is not a function. The reason for this is that sometimes the external expression of sizeof is a bit similar to a function, such as: I = sizeof (int, it is easy to mistakenly think that sizeof is a function. However, if sizeof is a function, sizeof I; (assuming I is an int variable) cannot be used because the parameters of the function cannot be enclosed in parentheses. In fact, this sizeof I; can run normally, which means sizeof is definitely not a function.
Sizeof usage
Sizeof plays the role of operators with the aura of keywords. It is mainly used to calculate the number of bytes occupied by a certain amount in the current system:
Can the brackets after sizeof be removed? If it is a specific amount, either a constant or a variable, you can directly write the sizeof amount, but if it is an operation on the type, you must add brackets:
Running result: Pay attention to exceptions. This indicates that sizeof converts the value of 'A' or '65 'to the int type by default, if you want to calculate the size of a direct constant of char or short, you need to convert it forcibly.
Summary
The standard documentation released by the company is the most convincing interpretation document when there is no doubt about the syntax.