ProgrammingModerate
int c = 0; for (int i = 10; i > 0; i -= 3) c++; printf("%d", c); What is printed?
- A. 3
- B. 4
- C. 5
- D. 10
Correct answer: B. 4
i takes the values 10, 7, 4 and 1, and then i becomes -2 and the loop ends.
More C Programming questions
- int c = 0, n = 3; do { c++; } while (n-- > 0); printf("%d", c); What is printed?
- int c = 0; for (int i = 0; i < 5; i++) { if (i == 2) continue; if (i == 4) break; c += i; } printf("%d", c); What is printed?
- int c = 0; for (int i = 0; i < 100; i++) c += i % 3 == 0; printf("%d", c); What is printed?
- unsigned n = 5; int c = 0; while (n-- > 0) c++; printf("%d", c); What is printed?
- int a = 0; for (int i = 0; i < 1000000; i++) a ^= i; printf("%d", a); What is printed?
- int x = 1, c = 0; while (x < 1000000000) { x = 3; c++; } printf("%d", c); What is printed (no overflow occurs)?