ProgrammingHard
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?
- A. 7
- B. 10
- C. 6
- D. 4
Correct answer: D. 4
i = 0, 1 and 3 add to c, since i = 2 is skipped and i = 4 breaks out. The sum is 0 + 1 + 3 = 4.
More C Programming questions
- 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)?
- A linear search over an array of length n finds the value only at the last position. How many comparisons does it make?
- Bubble sort with a swapped flag stops early. On an already sorted array of length n, how many passes run?