ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
int a[5] = {1,2,3,4,5};
int *p = a;
for (p = a; p < a + 5; p++) {
    if (p == a + 2) continue;
    printf("%d", *p);
}
  1. A. 12345
  2. B. 124
  3. C. Infinite loop
  4. D. 1245

Correct answer: D. 1245

continue in a for-loop still executes the increment p++ before re-checking the condition. When p==a+2 the printf is skipped (so 3 never prints) but p still advances, so the loop prints 1,2,4,5 -> "1245".

More C Programming questions

Exams that ask this topic