ProgrammingVery hardGATE CS · Campus placements
Adding two non-negative ints a and b without +, a loop repeats a = a ^ b and b = (old a & old b) << 1 until b is 0. Starting with a = 5 and b = 3, what does a finish as?
- A. 8
- B. 6
- C. 2
- D. 9
Correct answer: A. 8
The steps are (5,3) to (6,2), then (4,4), then (0,8), then (8,0). The carry chain ends with the sum 8.
More C Programming questions
- uint8t sum = (uint8t)(200 + 100); if (sum < 50) printf("yes"); else printf("no"); What is printed?
- char msg[] = "abc"; printf("%c", msg[msg[0] - 'a' + 1]); What is printed?
- for (int i = 0; i < 10; i++) for (int j = 1; j < 10; j = 2) count++; How many times does count increase?
- What does printf("%d %d", 17 / 5, 17 % 5) print?
- int x = 0; if (x = 5) printf("y"); else printf("n"); What is printed?
- Which expression clears the lowest three bits of an unsigned char x?