We can add two numbers without using plus operator, many of us quickly reply with below answer.
a – (-b)
But what we will do, if interviewer slightly twist question like this:
How to add two numbers without using arithmetic operator?
add(int a, int b)
{
while (b != 0)
{
int carry = a & b;
a = a ^ b;
b = carry << 1;
}
return a;
}