Recall & Review
beginner
What is memory allocation in C++?
Memory allocation is the process of reserving a portion of computer memory for use by a program during its execution.
Click to reveal answer
intermediate
What is the difference between
new and malloc() in C++?new allocates memory and calls the constructor, while malloc() only allocates memory without calling constructors.Click to reveal answer
beginner
How do you deallocate memory allocated with
new?Use
delete to free memory allocated with new. For arrays, use delete[].Click to reveal answer
beginner
What happens if you forget to deallocate memory in C++?
Forgetting to deallocate memory causes a memory leak, which wastes memory and can slow down or crash your program.
Click to reveal answer
intermediate
Explain the difference between stack and heap memory.
Stack memory stores local variables and is automatically managed. Heap memory is manually managed and used for dynamic allocation.
Click to reveal answer
Which operator is used to allocate memory dynamically in C++?
✗ Incorrect
The
new operator allocates memory dynamically and calls constructors in C++.How do you free memory allocated with
malloc()?✗ Incorrect
Memory allocated with
malloc() must be freed using free().What keyword is used to deallocate memory allocated with
new[]?✗ Incorrect
Use
delete[] to deallocate memory allocated with new[].What is a memory leak?
✗ Incorrect
A memory leak happens when allocated memory is not freed, causing wasted memory.
Where are local variables stored in C++?
✗ Incorrect
Local variables are stored on the stack, which is automatically managed.
Describe how dynamic memory allocation and deallocation work in C++.
Think about how you reserve and free memory manually.
You got /4 concepts.
Explain the difference between stack and heap memory with examples.
Consider where variables live during program execution.
You got /3 concepts.