← 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?
- A.free(a) only
- B.free(a), then free each a[i]
- C.free each a[i], then free(a)
- 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 →