Summary of the "original" sizeof operator

Source: Internet
Author: User

    1. The sizeof operator returns the number of bytes of an expression or a type name, and a constant expression that returns a value of size_t, note : sizeof right binds and is evaluated at compile time, not runtime
    2. Two forms:sizeof (type) and sizeof expression
    3. sizeof computes always the number of bytes of the type, and, if it is an array, multiplies the length of the array by the number of bytes of the element type, so for the second form, the type size of the expression result is computed, not the value of the expression.
    4. The sizeof operator is not the actual value of the expression, so sizeof *p, even if p is invalid , is safe, and gets the *p type size, Note : Not the size of the pointer
    5. A sizeof operation on a container object such as a vector returns only the size of the fixed part of the class and does not calculate the space occupied by the element in the container.
    6. The array parameter of the function is calculated as a pointer when the sizeof operation is performed; Elsewhere normal, the size of the array is multiplied by the number of element type bytes

C++11 New usage: Calculates the class public member size without having to provide a specific class, because no operations are required; Note : You cannot sizeof private members or protected members because they are not accessible externally

1 class a{2public:3     int A; 4 }; 5 sizeof A::a
This article links: "original" sizeof operator summary http://www.cnblogs.com/cposture/p/4935196.html

Summary of the "original" sizeof operator

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.