1
int x=7,y=2;

float f=x/y;

printf("%8.2f",(x/y));

For the above code, the output seems to be 0.00 but when we try to print the variable f the output is 3.00 with 4 blank spaces before it.Could someone tell me why?

kaylum
  • 13,833
  • 2
  • 22
  • 31
Priyam Das
  • 11
  • 1
  • 1
    `x/y` is an `int` (beeing `int`s both `x` and `y`) equal to `3` (integer division), it's UB to have mismatch between the format specifier of `printf` and the variables to be printed. – Bob__ Sep 08 '21 at 22:17

0 Answers0