ProgrammingModerate

struct K { int k; }; struct K list[3] = {{3}, {1}, {2}}; int sum = 0; for (int i = 0; i < 3; i++) sum = sum * 10 + list[i].k; printf("%d", sum); What is printed?

  1. A. 123
  2. B. 312
  3. C. 321
  4. D. 6

Correct answer: B. 312

Each pass shifts sum one decimal place and appends list[i].k in array order 3, 1, 2: 3, 31, 312. 123 assumes the structs are sorted, 321 builds the digits in reverse, and 6 just adds the keys.

More C Programming questions

Exams that ask this topic