0
0
Cprogramming~5 mins

Why dynamic memory is needed - Quick Recap

Choose your learning style9 modes available
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?
Amalloc()
Bprintf()
Cscanf()
Dmain()
Why is dynamic memory allocation useful?
AIt makes programs run faster always
BIt fixes memory size at compile time
CIt allows memory size to change during runtime
DIt removes the need to free memory
What is a risk of not freeing dynamic memory?
AFaster execution
BMemory leaks
CMore CPU usage
DSyntax errors
Static memory allocation is done when?
ADuring program execution
BAfter program ends
COnly in dynamic languages
DAt compile time
Which scenario needs dynamic memory?
AUser inputs unknown number of values
BDeclaring constants
CPrinting a fixed message
DFixed size array known at compile time
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.