我试图确定浮点数和double
可以使用的最大数字是多少。但它并没有按照我预期的方式存储,只能存储整数值。 double
应该包含8个字节的信息,足以容纳变量a,但它并没有正确地保留。它显示为1234567890123456768
,其中最后2个数字不同。当我将214783648
或任何数字存储在浮点变量b
的最后一个数字中时,它显示相同的值214783648
,这应该是极限了。到底是怎么回事?
double a;
float b;
int c;
a = 1234567890123456789;
b = 2147483648;
c = 2147483647;
printf("Bytes of double: %d\n", sizeof(double));
printf("Bytes of integer: %d\n", sizeof(int));
printf("Bytes of float: %d\n", sizeof(float));
printf("\n");
printf("You can count up to %.0f in 4 bytes\n", pow(2,32));
printf("You can count up to %.0f with + or - sign in 4 bytes\n", pow(2,31));
printf("You can count up to %.0f in 4 bytes\n", pow(2,64));
printf("You can count up to %.0f with + or - sign in in 8 bytes\n", pow(2,63));
printf("\n");
printf("double number: %.0f\n", a);
printf("floating point: %.0f\n", b);
printf("integer: %d\n", c);
return 0;
%zu
来打印sizeof
的输出结果。 - Sourav Ghoshlimits.h
中。 - barak manos