[Reprint] Various data types occupy memory size, as well as words, bytes, bits

foreword

Word is also called Word Byte is also called Byte Bit is also called bit
1 word=2 bytes
1 byte=8 bits
1K=1024B
1M=1024K
1G=1024M
1T=1024G

16-bit compiler
char: 1 byte
char* (ie pointer variable): 2 bytes
short int: 2 bytes
int: 2 bytes
unsigned int: 2 bytes
float: 4 bytes
double: 8 bytes
long: 4 bytes
long long: 8 bytes
unsigned long: 4 bytes
 
32-bit compiler
char: 1 byte
char* (ie pointer variable): 4 bytes (32-bit The addressing space is 2^32, that is, 32 bits, that is, 4 bytes. Similarly for 64-bit compilers)
short int: 2 bytes int: 4 bytes
unsigned int: 4 bytes
float: 4 bytes
double: 8 bytes
long: 4 bytes
long long: 8 bytes
unsigned long: 4 bytes

64-bit compiler
char: 1 byte
char* (ie pointer variable): 8 bytes
short int: 2 bytes
int: 4 bytes
unsigned int: 4 bytes
float: 4 bytes
double: 8 bytes
long: 8 bytes
long long: 8 bytes
unsigned long: 8 bytes various data types

=============================================================

It is related to the machine word length and the compiler: Therefore, the width of int, long int, and short int may vary with the compiler. But there are a few ironclad principles (made by ANSI/ISO): 1 sizeof(short int)<=sizeof(int) 2 sizeof(int)<=sizeof(long int) 3 short int should be at least 16 bits (2 words) section) 4 long int shall be at least 32 bits. unsigned means unsigned. For example: 16-bit compiler char: 1 byte char* (ie pointer variable): 2 bytes short int: 2 bytes int: 2 bytes unsigned int: 2 bytes float: 4 bytes double: 8 bytes long: 4 bytes long long: 8 bytes unsigned long: 4 bytes

32-bit compiler

char: 1 byte char* (ie pointer variable): 4 bytes (32-bit addressing space is 2^32, that is, 32 bits, that is, 4 bytes. The same is true for 64-bit compilers) short int : 2 bytes

int: 4 bytes unsigned int: 4 bytes float: 4 bytes double: 8 bytes long: 4 bytes long long: 8 bytes unsigned long: 4 bytes 64-bit compiler char : 1 byte char* (ie pointer variable): 8 bytes short int: 2 bytes int: 4 bytes unsigned int: 4 bytes float: 4 bytes double: 8 bytes long : 8 bytes long long: 8 bytes unsigned long: 8 bytes

 

foreword

Word is also called Word Byte is also called Byte Bit is also called bit
1 word=2 bytes
1 byte=8 bits
1K=1024B
1M=1024K
1G=1024M
1T=1024G

16-bit compiler
char: 1 byte
char* (ie pointer variable): 2 bytes
short int: 2 bytes
int: 2 bytes
unsigned int: 2 bytes
float: 4 bytes
double: 8 bytes
long: 4 bytes
long long: 8 bytes
unsigned long: 4 bytes
 
32-bit compiler
char: 1 byte
char* (ie pointer variable): 4 bytes (32-bit The addressing space is 2^32, that is, 32 bits, that is, 4 bytes. Similarly for 64-bit compilers)
short int: 2 bytes int: 4 bytes
unsigned int: 4 bytes
float: 4 bytes
double: 8 bytes
long: 4 bytes
long long: 8 bytes
unsigned long: 4 bytes

64-bit compiler
char: 1 byte
char* (ie pointer variable): 8 bytes
short int: 2 bytes
int: 4 bytes
unsigned int: 4 bytes
float: 4 bytes
double: 8 bytes
long: 8 bytes
long long: 8 bytes
unsigned long: 8 bytes various data types

=============================================================

It is related to the machine word length and the compiler: Therefore, the width of int, long int, and short int may vary with the compiler. But there are a few ironclad principles (made by ANSI/ISO): 1 sizeof(short int)<=sizeof(int) 2 sizeof(int)<=sizeof(long int) 3 short int should be at least 16 bits (2 words) section) 4 long int shall be at least 32 bits. unsigned means unsigned. For example: 16-bit compiler char: 1 byte char* (ie pointer variable): 2 bytes short int: 2 bytes int: 2 bytes unsigned int: 2 bytes float: 4 bytes double: 8 bytes long: 4 bytes long long: 8 bytes unsigned long: 4 bytes

32-bit compiler

char: 1 byte char* (ie pointer variable): 4 bytes (32-bit addressing space is 2^32, that is, 32 bits, that is, 4 bytes. The same is true for 64-bit compilers) short int : 2 bytes

int: 4 bytes unsigned int: 4 bytes float: 4 bytes double: 8 bytes long: 4 bytes long long: 8 bytes unsigned long: 4 bytes 64-bit compiler char : 1 byte char* (ie pointer variable): 8 bytes short int: 2 bytes int: 4 bytes unsigned int: 4 bytes float: 4 bytes double: 8 bytes long : 8 bytes long long: 8 bytes unsigned long: 8 bytes

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324642674&siteId=291194637