ProgrammingHard

struct Box { int w; int h; }; struct Box boxes[2] = {{2, 3}, {4, 5}}; int area = 0; for (struct Box *p = boxes; p < boxes + 2; p++) area += p->w * p->h; printf("%d", area); What is printed?

  1. A. 14
  2. B. 26
  3. C. 20
  4. D. 12

Correct answer: B. 26

p walks the array of structs, so the loop adds 2 x 3 = 6 and 4 x 5 = 20, giving 26. 14 adds all four fields instead of multiplying, and 20 keeps only the last box's area.

More C Programming questions

Exams that ask this topic