Add Two Numbers Without Using the Addition Operator



Add Two Numbers Without Using the Addition Operator..

Answer / Deenendra Pal Singh

In C, you can add two numbers without using the addition operator by bitwise XOR (^) and AND (&) operations. Here's an example: `((a ^ b) >> 31) ^ b`. This works because XOR gives a 1 if at least one of the corresponding bits in the operands is 1, and shifts it to the most significant bit. Then by XORing it again with the original number (b), the carry will be eliminated.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What is define c?

1 Answers  


52.write a “Hello World” program in “c” without using a semicolon? 53.Give a method to count the number of ones in a 32 bit number? 54.write a program that print itself even if the source file is deleted? 55.Given an unsigned integer, find if the number is power of 2?

9 Answers  


identify the in correct expression a.a=b=3=4; b.a=b=c=d=0; float a=int b=3.5; d.int a; float b; a=b=3.5;

8 Answers   TCS,


Define C in your own Language.

1 Answers   Motorola,


Where static variables are stored in memory in c?

1 Answers  


main is a predefined or user define function if user defined why? if predefined whay?

12 Answers   TCS,


Can you please explain the difference between malloc() and calloc() function?

1 Answers  


Given a piece of code int x[10]; int *ab; ab=x; To access the 6th element of the array which of the following is incorrect? (A) *(x+5) (B) x[5] (C) ab[5] (D) *(*ab+5} .

2 Answers   Oracle,


what does ‘segmentation violation’ mean?

1 Answers  


Write code for initializing one dimentional and two dimentional array in a C Program?

5 Answers   Deshaw, Edutech, GMD,


Explain what is the difference between functions getch() and getche()?

1 Answers  


Write a program to find the smallest and largest element in a given array in c language

11 Answers   Microsoft, Vembu,


Categories