Recall & Review
beginner
What is dynamic memory in C++?
Dynamic memory is memory allocated during program execution (runtime) using operators like
new and delete. 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 is fixed at compile time and can't change size during program run. Dynamic memory is needed when the amount of data is unknown or changes while the program runs.
Click to reveal answer
beginner
How does dynamic memory help with variable data sizes?
Dynamic memory lets programs allocate exactly the amount of memory needed at runtime, like when reading user input or loading files of unknown size.
Click to reveal answer
beginner
What is a real-life example of needing dynamic memory?
Imagine packing a suitcase without knowing how many clothes you'll bring. Dynamic memory is like having a suitcase that can grow or shrink as you add or remove clothes.
Click to reveal answer
intermediate
What happens if you don't free dynamic memory?
If you don't free dynamic memory with
delete, your program can waste memory (memory leak), which may slow down or crash the program over time.Click to reveal answer
Why do we use dynamic memory in C++?
✗ Incorrect
Dynamic memory allows programs to allocate memory while running, adapting to changing data sizes.
Which operator is used to allocate dynamic memory in C++?
✗ Incorrect
The
new operator allocates dynamic memory in C++.What is a risk of not freeing dynamic memory?
✗ Incorrect
Not freeing dynamic memory causes memory leaks, which waste memory and can crash programs.
When is dynamic memory especially useful?
✗ Incorrect
Dynamic memory is useful when data size is unknown or changes while the program runs.
Which of these is NOT a feature of dynamic memory?
✗ Incorrect
Dynamic memory is NOT fixed size at compile time; that describes static memory.
Explain why dynamic memory is needed in C++ programs.
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 you keep taking memory but never give it back.
You got /4 concepts.