ProgrammingHard

Which statement about memset(a, 0, sizeof a) for a 2D int array a[4][5] is correct?

  1. A. It sets every element of the whole array to zero, since sizeof a covers all rows
  2. B. It zeroes only the first row, because a is a pointer
  3. C. It is undefined for 2D arrays
  4. D. It zeroes only the first column

Correct answer: A. It sets every element of the whole array to zero, since sizeof a covers all rows

a is a real array object, so sizeof a is the total size in bytes, and memset clears the entire block.

More C Programming questions

Exams that ask this topic