Is their any way to add two numbers without using '+' operator or operator overloading? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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 Réponse
+ 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