ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
char g[3][4] = {"abc", "def", "ghi"};
for (int j = 0; j < 3; j++) putchar(g[2 - j][j]);
  1. A. gec
  2. B. ceg
  3. C. aei
  4. D. ieg

Correct answer: A. gec

The row runs 2, 1, 0 while the column runs 0, 1, 2, tracing the anti-diagonal from bottom left: g[2][0] = 'g', g[1][1] = 'e', g[0][2] = 'c'. 'aei' is the main diagonal.

More C Programming questions

Exams that ask this topic