#include<stdio.h> #include<limits.h> // 包含int的极限 #include<float.h> //包含float的极限 void main(){ printf("The bytes of int is %d, the bytes of float is %d \n", sizeof(int),sizeof(float)); printf("The max of int is %d, the min of int is %d\n",INT_MAX,INT_MIN); printf("The max of Float is %f, the min of Float is %.100f\n", FLT_MAX, FLT_MIN); //%.100f 显示小数点后100位 %f默认是小数点后6位 getchar(); /* Output The bytes of int is 4, the bytes of float is 4 The max of int is 2147483647, the min of int is -2147483648 The max of Float is 340282346638528860000000000000000000000.000000, the min of Float is 0.0000000000000000000000000000000000000117549435082228750000000000000000000000000000000000000000000000 对于以上结果的分析,为什么int和flaot同样是4个字节,表示的返回会不一样呢? 因为int的每一位都是数据位,4个字节,32位,一位当做符号位,其他都是有效的数据位,有限的32位只能表示2147483647。 而float 4个字节,32位,一个是符号位,其他31位中,有一部分是有效数据位,一部分是指数位,一部分是基数, 由于指数的原因,表示的范围就会更大 FLT_MAX是最大正负数,FLT_MIN是最小正负数 c语言默认是double 一般用浮点数表示。这种表达方式利用科学计数法来表达实数,即用一个尾数(Mantissa),一个基数(Base),一个指数(Exponent)以及一个表示正负的符号来表达实数 定点数包含整数和定点小数(0.123443 无整数部分) */ }
什么是浮点数
猜你喜欢
转载自www.cnblogs.com/luoxuw/p/11220171.html
今日推荐
周排行