double、long、unsigned、int、char类型数据所占字节数(C语言)

我喜欢简单粗暴一点的学习方式,怎么简单怎么来。。。。。

所以不会去去写太多没用的东西。

和机器字长及编译器有关系:

        所以,int,long int,short int的宽度都可能随编译器而异。

但有几条铁定的原则(ANSI/ISO制订的):

1 sizeof(short int)<=sizeof(int)

2 sizeof(int)<=sizeof(long int)

3 short int至少应为16位(2字节)

4 long int至少应为32位。

unsigned 是无符号的意思。

一、 16位编译器 

char :1个字节

char*(即指针变量): 2个字节

short int : 2个字节

int: 2个字节

unsigned int : 2个字节

float: 4个字节

double: 8个字节

long: 4个字节

long long: 8个字节

unsigned long: 4个字节

二、32位编译器

char :1个字节

char*(即指针变量): 4个字节

 short int : 2个字节

int: 4个字节

unsigned int : 4个字节

float: 4个字节

double: 8个字节 

long: 4个字节

 long long: 8个字节

unsigned long: 4个字节

三、64位编译器

 char :1个字节

char*(即指针变量): 8个字节

short int : 2个字节

int: 4个字节

unsigned int : 4个字节

float: 4个字节

double: 8个字节

long: 8个字节 (定义是long至少不小于int)

long long: 8个字节 (long long至少不小于long)

unsigned long: 8个字节

C 标准要求 float 类型精度7位  double双精度完全保证的有效数字最高是15位。

2^8=256

2^16=65536

2^32=4 294 967 296(40亿)

2^64=18446744073709551616 (188亿)

在做ACM题时,经常都会遇到一些比较大的整数。而常用的内置整数类型常常显得太小了:其中long 和 int 范围是[-2^31,2^31),即-2147483648~2147483647。而unsigned范围是[0,2^32),即0~4294967295。也就是说,常规的32位整数只能够处理40亿以下的数。

那遇到比40亿要大的数怎么办呢?这时就要用到C++的64位扩展了。

Dev-C++的g++编译器

scanf("%I64d",&a);
printf("%I64d",a);

VC的话

scanf("%lld",&a);
printf("%lld",a);

猜你喜欢

转载自blog.csdn.net/weixin_42143003/article/details/86515104