ProgrammingHardTCS NQT · Accenture

What is printed?

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

Correct answer: D. 3

The ternary picks the smaller entry of each row: min(3, 1) = 1 and min(4, 2) = 2, total 3. 4 takes the column minima (3 + 1) instead of the row minima.

More C Programming questions

Exams that ask this topic