🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Pointers and 2D Arrays: all 15 questions

Quiz: Pointers and 2D Arrays · Question 8 of 15

In a malloc matrix built as int a with one malloc per row, what is the correct way to free it?

In a malloc matrix built as int **a with one malloc per row, what is the correct way to free it?

  1. A.free(a) only
  2. B.free(a), then free each a[i]
  3. C.free each a[i], then free(a)
  4. D.Nothing — the rows are freed automatically
Answer & explanation

Correct answer: free each a[i], then free(a)

Free the rows while you still have their addresses, then free the array of row pointers.

Can you get the rest right without peeking?

Take the timed Quiz: Pointers and 2D Arrays quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →