0
0
C++programming~5 mins

Memory allocation and deallocation in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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++?
Amalloc
Balloc
Cnew
Dcreate
How do you free memory allocated with malloc()?
Afree
Bdelete
Crelease
Ddelete[]
What keyword is used to deallocate memory allocated with new[]?
Adelete
Bdelete[]
Crelease[]
Dfree
What is a memory leak?
AMemory allocated but never used
BMemory freed twice
CMemory allocated on stack
DMemory allocated but not freed
Where are local variables stored in C++?
AStack
BHeap
CGlobal memory
DCache
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.