比特(bit),即一个二进制位 ,例如100011就是6比特;
字节(byte),是计算机中数据类型最基本的单位,8bit组成1byte;1024byte组成1KB。
short(短整型),占2byte即16位,两个字节。
int(整型),占4byte即32位,一个int型数据的长度用4个字节来存储。
float(浮点型)占4byte即32位。
double(双精度浮点型)占8byte即64位。
#include <stdio.h>
int main()
{
printf("sizeof( char ): %zd\n", sizeof(char));
printf("sizeof( short int ): %zd\n", sizeof(short int));
printf("sizeof( int ): %zd\n", sizeof(int));
printf("sizeof( float ): %zd\n", sizeof(float));
printf("sizeof( long int ): %zd\n", sizeof(long int));
printf("sizeof( long long int ): %zd\n", sizeof(long long int));
printf("sizeof( double ): %zd\n", sizeof(double));
printf("sizeof( long double ): %zd\n", sizeof(long double));
printf("sizeof( size_t ): %zd\n", sizeof(size_t)); //long unsigned int
printf("sizeof( void* ): %zd\n\n", sizeof(void*));
return 0;
}
64位centos7 gcc -m32
sizeof( char ): 1
sizeof( short int ): 2
sizeof( int ): 4
sizeof( float ): 4
sizeof( long int ): 4
sizeof( long long int ): 8
sizeof( double ): 8
sizeof( long double ): 12
sizeof( size_t ): 4
sizeof( void* ): 4
64位centos7 gcc
sizeof( char ): 1
sizeof( short int ): 2
sizeof( int ): 4
sizeof( float ): 4
sizeof( long int ): 8
sizeof( long long int ): 8
sizeof( double ): 8
sizeof( long double ): 16
sizeof( size_t ): 8
sizeof( void* ): 8
64位win10 vs Debug x86
sizeof( char ): 1
sizeof( short int ): 2
sizeof( int ): 4
sizeof( float ): 4
sizeof( long int ): 4
sizeof( long long int ): 8
sizeof( double ): 8
sizeof( long double ): 8
sizeof( size_t ): 4
sizeof( void* ): 4
64位win10 vs Debug x64
sizeof( char ): 1
sizeof( short int ): 2
sizeof( int ): 4
sizeof( float ): 4
sizeof( long int ): 4
sizeof( long long int ): 8
sizeof( double ): 8
sizeof( long double ): 8
sizeof( size_t ): 8
sizeof( void* ): 8