ProgrammingHardTCS NQT · Infosys

What is printed?

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

Correct answer: A. 4 5 5

The maximum of each adjacent pair is max(4,2) = 4, max(2,5) = 5 and max(5,1) = 5.

More C Programming questions

Exams that ask this topic