-2

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; 
Caleb
  • 124,013
  • 19
  • 183
  • 272

1 Answers1

4

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.

StardustGogeta
  • 3,331
  • 2
  • 18
  • 32