ProgrammingVery hardGATE CS · Campus placements
int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int (*ops[])(int, int) = {add, sub, add}; int r = 10; for (int i = 0; i < 3; i++) r = ops[i](r, i + 1); What is r after the loop?
- A. 8
- B. 12
- C. 10
- D. 15
Correct answer: B. 12
Step by step: add(10,1) = 11, sub(11,2) = 9, add(9,3) = 12. The table selects the operation per step, applied to the running value.
More C Programming questions
- uint32t a = 4000000000u; uint32t s = a + a; What is s?
- uint32t lo = 3000000000u, hi = 3500000000u; uint32t mid = (lo + hi) / 2; What is mid?
- uint32t x = 0u; Which statement about the test (x & (x - 1)) == 0 is correct?
- uint8t x = 0x81; uint8t r = (uint8t)((x >> 1) | (x << 7)); What is r?
- What is the value of 1 << 2 + 3 in C?
- int x = 2; printf("%d", x & 1 == 1); prints what?