Search for errors in a simple add function

This was asked in an interview. "There is an error in the bottom function, what is it?" It is simple to add the function c, and the main function calls it. Given some key - "Give a different set of input values, check and find the error."

int add (int x, int y) { return x + y; } 
+4
source share
1 answer

The problem can be a whole overflow if x+y greater than INT_MAX or less than INT_MIN . So use long long as return type.

+11
source

Source: https://habr.com/ru/post/1489656/


All Articles