Why 10.5 become 10.0 after swap ?
#define swap(a,b) {int aux; aux=a; a=b; b=aux;}
float x=10.5, y=3.75;
swap(x,y);
// x=3.75, y=10.0;
Why 10.5 become 10.0 after swap ?
#define swap(a,b) {int aux; aux=a; a=b; b=aux;}
float x=10.5, y=3.75;
swap(x,y);
// x=3.75, y=10.0;
aux
is of type int
, which will drop the decimal part of the argument a
passed to swap
. In this case, swap(x, y)
drops the decimal part of x
before it is assigned to y
at the end.