sizeof is both a keyword and an operator (operator), but not a function!

Source: Internet
Author: User

is sizeof a key word?

sizeof is the key word , which is beyond doubt. You cannot define sizeof as any identifier. See the instructions in the C language standard documentation:

Does sizeof have an operator (operator)?

In C,sizeof is an operator (operator)and is the only operator that appears as a word, which is used to calculate how many bytes are required to hold a certain amount, and its associativity is right-to-left. See the instructions in the C language standard documentation:

is sizeof a function?

sizeof is not a function . The main reason for this is that sometimes the external performance of sizeof is somewhat analogous to a function, such as: i = sizeof (int), and it is easy to mistake the fact that sizeof is a function. But if sizeof is a function, then sizeof I; (assuming i is an int variable) This formula must not be true, because the function's parameters cannot be enclosed in parentheses. In fact, this sizeof I; it works, which means that sizeof is definitely not a function.

sizeof Usage

sizeof is a key-word halo that plays the role of an operator. It is used primarily to calculate the number of bytes required for a certain amount in the current system:

Can the parentheses behind the sizeof be removed? If it is a specific amount, either constant or variable, you can write the sizeof amount directly, but if you are working on a type, you must add parentheses:

Operation Result:

Notice the abnormal situation, this shows: sizeof face direct volume such as ' A ', 65, and so on, it will default to the int type calculation, if you need to calculate the direct constant size of char or short, you need to cast.

Summary

When it comes to grammatical doubt, the standard document that is published is the most persuasive of the explanatory documents.

sizeof is both a keyword and an operator (operator), but not a function!

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.