Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How C Language Converts Data Types
How C Language Converts Data Types
For example, you declare an integer a, b and calculate a floating point C.

int a=5,b = 2;

Floating c = a/b;

C gets a value of 2.0, not 2.5.

Therefore, it is necessary to convert data types in the following ways to solve this problem:

Float c = float(A)/B// If A is forcibly converted to a floating point, then B will also become a floating point to participate in the operation.

Or float = float(A)/float(B)// Convert both A and B into floating-point types for operation.

The format is (type name) variable or numeric value.

Note: the cast data type is temporary, and A and B are still integer variables.