C + + does not specify the storage size of various data types in memory, depending on the different compiler, to know the current compiler to the various data types allocated size, can be obtained through the sizeof operator.
Use Method 1:
sizeof (data type)
Use Method 2:
sizeof (variable name or constant name or expression)
sizeof (int)
Or
int A;
sizeof (a)
[CPP]View PlainCopy
- Spatial allocation of data types
- #include <iostream>
- Using namespace std;
- int main ()
- {
- cout<<"vc++6.0 compilation environment, the amount of memory space (in bytes) of various data type variables" <<endl;
- cout<<"sizeof (int)" <<sizeof (int) <<endl;
- cout<<"sizeof (short int)" <<sizeof (short) <<endl;
- cout<<"sizeof (long int)" <<sizeof (long) <<endl;
- cout<<"sizeof (unsigned int)" <<sizeof (unsigned) <<endl;
- cout<<"sizeof (unsigned short int)" <<sizeof (unsigned ) <<endl;
- cout<<"sizeof (unsigned long int)" <<sizeof (unsigned long) <<endl;
- cout<<"sizeof (char)" <<sizeof (char) <<endl;
- cout<<"sizeof (float)" <<sizeof (float) <<endl;
- cout<<"sizeof (double)" <<sizeof (double) <<endl;
- cout<<"sizeof (long Double)" <<sizeof (long Double) <<endl;
- return 0;
- }
Run results
sizeof operator to get the number of bytes in memory of various data types--gyy collation