Recall & Review
beginner
What is dynamic memory in C?
Dynamic memory is memory allocated during program execution using functions like malloc(), calloc(), and realloc(). It allows flexible use of memory based on program needs.
Click to reveal answer
beginner
Why can't we always use static memory allocation?
Static memory allocation fixes memory size at compile time, which can waste memory or limit program flexibility if the exact size is unknown or changes during runtime.
Click to reveal answer
beginner
How does dynamic memory help with unknown data sizes?
Dynamic memory lets programs allocate exactly the amount of memory needed at runtime, which is useful when data size is unknown or changes, like reading user input or files.
Click to reveal answer
beginner
What happens if you don't free dynamic memory?
If dynamic memory is not freed using free(), it causes memory leaks, which waste memory and can slow down or crash programs over time.
Click to reveal answer
beginner
Give a real-life example where dynamic memory is needed.
Imagine a photo app that loads pictures of different sizes. It can't reserve fixed memory for all photos, so it uses dynamic memory to allocate space as needed for each photo.
Click to reveal answer
Which C function is used to allocate dynamic memory?
✗ Incorrect
malloc() allocates memory dynamically during program execution.
Why is dynamic memory allocation useful?
✗ Incorrect
Dynamic memory allows programs to allocate memory as needed during runtime.
What is a risk of not freeing dynamic memory?
✗ Incorrect
Not freeing dynamic memory causes memory leaks, wasting memory.
Static memory allocation is done when?
✗ Incorrect
Static memory is allocated at compile time and cannot change during execution.
Which scenario needs dynamic memory?
✗ Incorrect
When the number of inputs is unknown, dynamic memory lets you allocate space as needed.
Explain why dynamic memory is important in C programming.
Think about programs that don't know how much data they will handle before running.
You got /4 concepts.
Describe what can happen if dynamic memory is not properly managed.
Consider what happens if memory is allocated but never given back.
You got /4 concepts.