🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Dynamic Memory: questions with answers

10 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. Which function allocates memory AND sets it to zero?
  2. Q2. What is a memory leak?
  3. Q3. What is the correct way to allocate an array of 10 ints?
  4. Q4. After free(p);, what should you do to avoid a dangling pointer?
  5. Q5. Which header declares malloc and free?
  6. Q6. What does this print? (code)
  7. Q7. Why is p = realloc(p, newSize); risky?
  8. Q8. A function returns a pointer to memory it got from malloc. Is that pointer still valid after the function returns?
  9. Q9. What happens if you call free(p) twice on the same pointer?
  10. Q10. What does this print? (code)