- 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
- Two forms:sizeof (type) and sizeof expression
- 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.
- 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
- 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.
- 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