开发者

What's the easiest way to work out the difference between two positive integers?

开发者 https://www.devze.com 2023-01-01 11:22 出处:网络
I just need to know the difference between two int variables a开发者_开发百科 and b. I\'m new to Objective-C.int diff = a - b;

I just need to know the difference between two int variables a开发者_开发百科 and b.

I'm new to Objective-C.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消