How to check integer overflow in C? - by Ganker There's (1): // assume x,y are non-negative if(x > max - y) error; And (2): // assume x,y are non-negative int sum = x + y; if(sum < x || sum < y) error; Whichs is preferred or is there a better way. Read the article