The number of bytes consumed by the C basic data type can be obtained by the following example:
#include <stdio.h>intMainvoid) {printf ("char size=%d \ n",sizeof(Char)); printf ("int size=%d \ n",sizeof(int)); printf ("long size=%d \ n",sizeof(Long)); printf ("float size=%d \ n",sizeof(float)); printf ("double size=%d \ n",sizeof(Double)); printf ("char* size=%d \ n",sizeof(Char*)); printf ("int* size=%d \ n",sizeof(int*)); printf ("long* size=%d \ n",sizeof(Long*)); printf ("float* size=%d \ n",sizeof(float*)); printf ("double* size=%d \ n",sizeof(Double*)); printf ("char[] size=%d \ n",sizeof(Char[2])); return 0;}
Execution Result:
$./size.exe
Char size=1
int size=4
Long size=8
Float size=4
Double size=8
char* size=8
int* size=8
long* size=8
float* size=8
double* size=8
Char[] size=2
Above, unit is byte, one byte is 8 bit
It is important to note that any type of pointer variable occupies 8 bytes
C language basic data type size