#C++ Day3 Sep 11 2025

#include <iostream>

using namespace std;

int main()

// short 2字节     00       2 ^16   [-2 ^ 15 ~2 ^ 15 – 1]  [-32768~32767]

// int 4字节       0000     2 ^ 16  [-2 ^ 31 ~2 ^ 31 – 1] [-2147483648~2147483647]

// long 4字节 8字节 0000     2 ^ 16  [-2 ^ 31 ~2 ^ 31 – 1]

// long long 8字节 00000000  2 ^ 16 [-2 ^ 63 ~2 ^ 63 – 1]

//[l,r]

// range:r-l+1

//make it close to the range can save the space ,so watch out the range

{

    short a = 32768; // will be get out of the range,and turn to the loop’s start -32768

    int b = 2147483648;

    long c = 1;

    long long d = 1;

    cout << “a=” << a << endl;

    a = 32769;

    cout << “a2=” << a << endl; // show out -32767

    cout << “b=” << b << endl;

    cout << “c=” << c << endl;

    cout << “d=” << d << endl;

    return 0;

}

//new reserver symbol sizeof()

#include <iostream>

using namespace std;

int main()

{

    short a = 1;

    int b = 1;

    long c = 1;

    long long d = 1;

    cout << sizeof(short) << endl;

    cout << sizeof(int) << endl;

    cout << sizeof(long) << endl;

    cout << sizeof(long long) << endl;

    cout << sizeof(a) << endl;

    cout << sizeof(b) << endl;

    cout << sizeof(c) << endl;

    cout << sizeof(d) << endl;

    return 0;

}

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

int main()

#define eps 1e-7

// float 0000 4bytes

/// double 00000000 8bytes

// if you want to solve the question,must use double ,or you will miss the acuracy

// to judge the accuration of float, please make it minus in a small range

{

    float a = 13.1415926f;

    double b = 13.1415926;

    cout << setprecision(10) << a << endl;

    cout << setprecision(10) << b << endl;

    a = 13.1415926f;

    b = 13.141592611111111111;

    cout << setprecision(10) << a << endl;

    cout << setprecision(30) << b << endl; // if you make it out of range ,can still display the wrong number

    cout << sizeof(a) << endl;

    cout << sizeof(b) << endl;

    double c = 1.5e5; // 1.5*10^5

    cout << c << endl;

    double d = 1.5e-5; // 1.5*10^-5

    cout << d << endl;

    double x = 1.0 / 123123111123123123 * 123123111123123123; // when the float is large enough,must will have the error

    cout << x << endl;

    if (fabs(x – 1) < 0.00000001)

    {

        cout << “one two” << endl;

    }

    if (fabs(x – 1) < eps)

    {

        cout << “one two” << endl;

    }

    return 0;

}