在C ++中,int和float类型在内存中占用4个字节(在我的机器中),然后浮点数如何表示比int大得多的数字?
#include <iostream>
#include<climits>
#include<cfloat>
using namespace std;
int main(int argc, char **argv)
{
cout<<fixed;
cout<<"Size of int: "<<sizeof(int)<<" bytes."<<endl;
cout<<"Size of float "<<sizeof(float)<<" bytes."<<endl;
cout<<"Int ranges from "<<INT_MIN<<" to "<<INT_MAX<<endl;
cout<<"Float ranges from "<<FLT_MIN<<" to "<<FLT_MAX<<endl;
return 0;
}
该程序提供以下输出:
int的大小:4个字节。
float的大小为4个字节。
Int范围从-2147483648到2147483647
浮点范围从0.000000到340282346638528859811704183484516925440.000000