C++Primer Fifth Edition: Exercise 2.1 2.2

  1. Exercise 2.1 The
    minimum size of int is 16 bits, the minimum size of 2 bytes
    long is 32 bits, the minimum size of 4 bytes
    long long is 64 bits, the minimum size of 8 bytes
    short is 16 bits, and the minimum size is 2 bytes.

    Signed types can represent integers. Negative numbers and 0. Unsigned types can only represent values ​​greater than or equal to 0.
    All bits in unsigned types are used to store values. For example, 8-bit unsigned char can represent values ​​in the range of 0 to 255. , And signed char means the range is -128~127

    Float is represented by 1 word (32 bits or 4 bytes).
    Double is represented by 2 words (64 bits or 8 bytes). The
    precision of float is not enough and the calculation cost of double-precision floating-point numbers and single-precision floating-point numbers is almost the same.

  2. Exercise 2.2
    Interest rate: double interest rate is generally a decimal, double is more accurate than float and the calculation cost of the two is not large.
    Principal: unsigned int(unsigned) The principal is generally a positive integer, unsigned means a large value, saving memory.
    Payment: double plus interest rate For decimals, use double

Guess you like

Origin blog.csdn.net/Xgggcalled/article/details/108694688