Is their any way to add two numbers without using '+' operator or operator overloading? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is their any way to add two numbers without using '+' operator or operator overloading?

Is this possible by embedding assembly code into our code?

9th Nov 2017, 7:17 PM
Alfaf Shaikh
Alfaf Shaikh - avatar
1 Answer
+ 6
You can use bitwise addition: int add(int x, int y) { while(y != 0) { int c = (x & y); x = x ^ y; y = c << 1; } return x; }
9th Nov 2017, 7:49 PM
ChaoticDawg
ChaoticDawg - avatar