Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Why is 1 divided by 2 equal to 0 in C language?
Why is 1 divided by 2 equal to 0 in C language?
Because 1 is an int constant by default, the output result of 1/2 is consistent with the dividend, and 0 is output (0.5 is converted into 0 after int type conversion).

It should be noted here that in C language division, the data type of the result will be converted into the data type of the dividend.

For example:

int? Answer? =? 4;

int? b? =? 3;

Floating? d? =? 5;

int? c? =? a/b; //? The result of variable c is 1, which was originally 4/3= 1.333 (in order to be consistent with the type of dividend A, the integer part is taken and the decimal part is discarded).

Floating? e? =? D/A; //? The value of e is 1.25, because d is of float type.