C++实型

156 阅读1分钟
#include<iostream>
using namespace std;


int main(){
    
    //1. 单精度 float
    //2. 双精度 double
    float f1 = 3.14f;  //加上f显式告诉编译器是单精度
    cout << "f1的值:" << f1 << endl;
    double d1 = 3.14;
    cout << "d1的值:" << d1 << endl;

    //统计float和double占用内存空间
    cout << "float 占用内存空间为:" << sizeof(f1) << endl;
    cout << "double 占用内存空间为:" << sizeof(d1) << endl;

    //科学计数法
    float f2 = 3e2;  // 3 * 10 ^ 2
    float f3 = 3e-2;  // 3 * 0.1 ^ 2
    cout << "f2=" << f2 <<endl;
    cout << "f3=" << f3 <<endl;


    cout << "hello world!" << endl;
    system("pause");
    return 0;
}


1638171415420_30F36892-EB76-49a1-9984-B53EC7F8770E.png