1. ## pointers swap function

Need to write a function with 2 floats that make the first argument "a - b" and the second one "b - a", then print the 2 with .2 precision.
Compiles but output is not correct.
Can anyone tell me why? and maybe suggest me a book with a good pointers chapter? My slides are confusing.

This is my code.
Code:
```#include <stdio.h>

float diff_abs(float*, float*);

float diff_abs(float *a, float *b)
{
*a = *a - *b;
*b = *b - *a;
}

int main(void)
{
float x;
float y;
scanf("%f", &x);
scanf("%f", &y);
diff_abs(&x,&y);
printf("%.2f\n", x);
printf("%.2f", y);
return 0;
}```

2. I would guess that the problem is that you modify *a before using it, hence the computation for *b is incorrect. If so, then a solution is to save the original value of *a before assigning to it, then use that original value to compute the new value of *b.

It would be more helpful if you gave a descriptive overview of what diff_abs was supposed to do (rather than just restate how you implemented it), along with your test input, expected output, and actual output.

3. > Can anyone tell me why?
Because you're treating computational calculations (on finite machines) as being equivalent to mathematical operations.

Mathematically, you can add 10100 and 10-100 with perfect accuracy, but this doesn't happen on real finite machines. Small numbers just get lost in the noise.

Code:
```    float t1 = *a - *b;
float t2 = *b - *a;
*a = t1;
*b = t2;```

4. Thanks, now it works. I didn't explain much more because it didn't have much more in it, except for test input|output. I'll get back to the theory some more.