How do I check if A+B exceed long long? (both A and B is long long) [duplicate]
问题 This question already has an answer here: How do I detect unsigned integer multiply overflow? 31 answers I have two numbers: A and B . I need to calculate A+B somewhere in my code. Both A and B are long long , and they can be positive or negative . My code runs wrong, and I suspect the problem happens when calculating A+B . I simply want to check if A+B exceed long long range. So, any method is acceptable, as I only use it for debug. 回答1: Overflow is possible only when both numbers have the