← 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 →- Q1. Which function allocates memory AND sets it to zero?
- Q2. What is a memory leak?
- Q3. What is the correct way to allocate an array of 10 ints?
- Q4. After free(p);, what should you do to avoid a dangling pointer?
- Q5. Which header declares malloc and free?
- Q6. What does this print? (code)
- Q7. Why is p = realloc(p, newSize); risky?
- Q8. A function returns a pointer to memory it got from malloc. Is that pointer still valid after the function returns?
- Q9. What happens if you call free(p) twice on the same pointer?
- Q10. What does this print? (code)