views:

96

answers:

1

I just need to know the difference between two int variables a and b.

I'm new to Objective-C.

+6  A: 
int diff = a - b;

or if you need the absolute difference:

int abs_diff = abs(a - b);

and if there is any chance that your expression might overflow:

int abs_diff = max(a, b) - min(a, b);
Paul R
+1, answer revoked. Someone who knows is better than someone who's guessing.
Matchu
@GregS: Thanks - Garry didn't actually say *absolute difference* but I've now covered that possibility too.
Paul R
`abs`. That's what I was looking for. Thanks!
Garry
@GregS: Sorry, I meant absolute difference :)
Garry