ProgrammingModerateTCS NQT · Infosys

What is printed?

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

Correct answer: A. 1

The comparison is strict, so the first maximum 9 at index 1 is kept and the later 9 at index 3 does not replace it.

More C Programming questions

Exams that ask this topic