加f与不加f的区别
用float跟double分别表示
默认情况下 输出一个小数,会显示出6位有效数字
各自占用的内存空间
科学计数法以及代码演示
#include<iostream>
using namespace std;
int main()
{
//1、单精度,float
//2、双精度 double
float f1 = 3.1415926f;
cout << "f1=" << f1 << endl;
double d1 = 3.1415926;
cout << "d1=" << d1 << endl;
//统计float和double占用内存空间
cout << "float占用内存空间为:" << sizeof(float) << endl;
cout << "double占用内存空间为:" << sizeof(double) << endl;
//科学计数法
float f2 = 3e2f;//3*10^2
cout << "f2=" << f2 << endl;
cout << "f2占用内存空间为:" << sizeof(f2) << endl;
float f3 = 3e-2f;//3*0.1 ^2
cout << "f3=" << f3 << endl;
cout << "f3占用内存空间为:" << sizeof(f3) << endl;
system("pause");
return 0;
}