Sizeof is both a keyword and an operator, but not a function !, Sizeof Operator

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.