ProgrammingHardTCS NQT · Infosys
int n = 5; int r = n++ * 2; What are the final values of r and n?
- A. r = 10, n = 6
- B. r = 12, n = 6
- C. r = 10, n = 5
- D. r = 12, n = 5
Correct answer: A. r = 10, n = 6
n++ yields the old value 5, so r is 10, and n is incremented to 6. The side effect is applied once with no conflicting read, so the code is well defined.
More C Programming questions
- 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…
- 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?