This was asked in an interview. "There is a bug in the below function, what is it?". It is simple add c function and main function calls it. Given some clue -- "Give different set of input values, test and find bug".
int add (int x, int y)
{
return x + y;
}
The problem can be integer overflow occurs if x+y
is greater than INT_MAX
or less than INT_MIN
. So use long long
as return type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With