请问一下,编写c语言程序的时候什么时候用int 什么时候用float double类型的函数??

如题所述

你要先知道不同类型的取值范围

char -128 ~ +127 (1 Byte)
short -32767 ~ + 32768 (2 Bytes)
unsigned short 0 ~ 65536 (2 Bytes)
int -2147483648 ~ +2147483647 (4 Bytes)
unsigned int 0 ~ 4294967295 (4 Bytes)
long == int
long long -9223372036854775808 ~ +9223372036854775807 (8 Bytes)
double 1.7 * 10^308 (8 Bytes)
unsigned int 0~4294967295 
long long的最大值:9223372036854775807
long long的最小值:-9223372036854775808
unsigned long long的最大值:1844674407370955161
__int64的最大值:9223372036854775807
__int64的最小值:-9223372036854775808
unsigned __int64的最大值:18446744073709551615

float与double的不同

类型   比特数    有效数字 数值范围 
float   32     6-7    -3.4*10(-38)~3.4*10(38) 
double   64    15-16   -1.7*10(-308)~1.7*10(308) 
long double 128 18-19 -1.2*10(-4932)~1.2*10(4932)

在实际使用中,你按照你自己的值的可能范围去选择合适的类型,比如说你有一个数字,整数,最大50000,那按上面的表,当然是不能用short,可以用int或者unsigned short,double与float一样,有效数字不同,如果你有小数是0.123456789,数字位有10位,那用float来表示的话,结果就会变成0.123457,后面三位都被四舍五入了

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-10-11
这个区别还是有的,short int 16位,int 32位 ; long 如果64为系统的话,就是64位; float为单精度; double为双精度;就是二者的精度值不一样,要求精度高的话,就用double好了;
相似回答