Summary of SizeOf

xiaoxiao2021-03-06  65

SIZEOF summary:

basic type:

SizeOf (BOOL) = 1;

Sizeof (char) = 1;

SIZEOF (Short) = 2;

SIZEOF (long) = 4;

SIZEOF (int) = 4;

SizeOf (float) = 4;

SIZEOF (DOUBLE) = 8;

SIZEOF (STRING) = 16;

SIZEOF (Vector ) = 16;

Element type T, number of array array: ARRAY:

SizeOf (array) = n * sizeof (t);

Pointers and quotes:

When SIZEOF acts on the pointer variable, the result is always 4, and when the reference variable is actued, the result is equal to the Size of the referenced variable. Such as:

Double A; double * b = & a; double & c = a;

SIZEOF (B) = 4; SizeOf (C) = 8.

class:

1) Class without parental class: Its SIZE is equivalent to the sum of the Size of its non-static member variable:

Class ctest1 {

PUBLIC:

Int a, b

Static Double C;

Double D;

}

SIZEOF (ctest1) = sizeof (a) sizeof (b) sizeof (d) = 4 4 8 = 16;

Why is it right? Since the variable can only store the beginning of the word in memory, the order of defining member variables may affect the size of the class, such as the above CTEST1

Class ctest2 {

PUBLIC:

Int a;

Static Double C;

Double D;

INT B;

}

SIZEOF (CTEST2) = 24; It can be seen that the order in which a member variable in the class will affect the utilization of memory, which is related to the compiler alignment.

2) Detective class: Need to add Size of its base class

Class Ctest3: ctest1 {

PUBLIC:

Int E;

}; sizeof (ctest3) = 24

3) Class ctest4 {}; // sizeof (ctest4) = 1 class ctest5 {Virtual ~ ctest5 () {}}; // sizeof (ctest5) = 4

转载请注明原文地址:https://www.9cbs.com/read-84695.html

New Post(0)