ProgrammingHardTCS NQT · Wipro

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int a[] = {1, 3, 2, 5}, c = 0;
    for (int *p = a; p < a + 4; p++)
        if (*p > 2) c++;
    printf("%d", c);
}
  1. A. 1
  2. B. 3
  3. C. 2
  4. D. 4

Correct answer: C. 2

Only 3 and 5 exceed 2, so the pointer loop counts two elements.

More C Programming questions

Exams that ask this topic