ProgrammingModerate
int n = 0; do { n += 2; } while (n < 7); printf("%d", n); What is printed?
- A. 6
- B. 4
- C. 2
- D. 8
Correct answer: D. 8
The body runs before each test: n = 2, 4, 6, then 6 < 7 still holds so one more pass gives 8, and 8 < 7 ends the loop. 6 stops one pass early, 4 is the number of iterations, and 2 assumes a do-while body runs only once.
More C Programming questions
- unsigned char c = 0; c -= 1; printf("%d", c); What is printed?
- int m = 2147483647; printf("%d", m / 2); What is printed with a 32-bit int?
- How many subsets of the bit positions of mask 22 (binary 10110) are visited, counting the empty subset? Compute with this program. c…
- What is printed? c #include <stdio.h> int main(void) { unsigned a = 0xB6, b = 0x3C; printf("%u", a & ~b); }
- What is printed? This program tries every subset of {3, 5, 6} and prints the largest XOR of a subset (the empty subset counts as 0). c…
- What is printed? c #include <stdio.h> char g[3][4] = {"110", "010", "011"}; int fill(int r, int c) { if (r < 0 || c < 0 || r >= 3 || c >=…