🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Dynamic Memory: all 10 questions

Quiz: Dynamic Memory · Question 7 of 10

Why is p = realloc(p, newSize); risky?

Why is p = realloc(p, newSize); risky?

  1. A.realloc always moves the data
  2. B.If realloc fails it returns NULL, and the only pointer to the old block is lost, leaking it
  3. C.realloc frees p twice
  4. D.realloc cannot make a block bigger
Answer & explanation

Correct answer: If realloc fails it returns NULL, and the only pointer to the old block is lost, leaking it

Store the result in a temporary pointer first, and assign it to p only if it is not NULL.

Can you get the rest right without peeking?

Take the timed Quiz: Dynamic Memory quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →