Recall & Review
beginner
What is a memory leak in C programming?
A memory leak happens when a program allocates memory but never frees it, causing the memory to stay used and unavailable for other parts of the program or system.
Click to reveal answer
beginner
Why are memory leaks a problem in programs?
Memory leaks reduce the available memory over time, which can slow down or crash programs because they run out of memory to use.
Click to reveal answer
beginner
Which C functions are commonly used to allocate and free memory?
malloc() is used to allocate memory, and free() is used to release that memory back to the system.
Click to reveal answer
intermediate
What happens if you call free() on a pointer twice?
Calling free() twice on the same pointer can cause undefined behavior, which may crash the program or corrupt memory.
Click to reveal answer
intermediate
How can you detect memory leaks in C programs?
You can use tools like Valgrind or AddressSanitizer to find memory leaks by tracking allocated memory that was never freed.
Click to reveal answer
What does a memory leak cause in a program?
✗ Incorrect
A memory leak means memory is allocated but not freed, causing it to stay used.
Which function is used to free allocated memory in C?
✗ Incorrect
free() releases memory that was allocated with malloc() or similar functions.
What is a common cause of memory leaks?
✗ Incorrect
Not freeing allocated memory causes memory leaks.
Which tool can help detect memory leaks in C programs?
✗ Incorrect
Valgrind tracks memory usage and can find leaks.
What happens if you free memory twice?
✗ Incorrect
Freeing memory twice can cause crashes or corrupt memory.
Explain what a memory leak is and why it is harmful in C programs.
Think about what happens when memory is allocated but never given back.
You got /3 concepts.
Describe how you can prevent memory leaks when using malloc() in C.
Consider the steps after allocating memory.
You got /4 concepts.