ProgrammingHard

int *a = calloc(4, sizeof *a); int sum = 0; for (int i = 0; i < 4; i++) sum += a[i]; printf("%d", sum); What is printed?

  1. A. 4
  2. B. -1
  3. C. garbage
  4. D. 0

Correct answer: D. 0

calloc sets every element to zero, so the sum of the four ints is 0. malloc alone would leave the values indeterminate.

More C Programming questions

Exams that ask this topic