C language: a query about floating-point numbers changing into integers?
Because your a is still in the form of floating point number after explicit conversion, but the value does become 3, the key lies in the difference between double-precision floating point number and integer and the stack output structure adopted by printf function; The number of digits of floating-point type is higher than that of integer type, so after entering a, the number of effective digits is smaller than that of double-precision floating-point type, so there are a bunch of zeros, such as: 000000000000003.6538+042857000000000,0000003. But when reading, you use an integer type. Depending on the compiler, you may read only the first 8 or 4 digits, and there are so many zeros in front of your number. Secondly, int(a) is an integer destructor of c++ ((int)a is a forced conversion (display conversion)), which is used to directly extract the integer part of A. It is more accurate to use this as a floating-point integer, so it is recommended to use int(a) to output as% d.