C- Memory Allocation Questions and Answers
Practice ModeShowing 10 of 28 questions
Q11
What does malloc() return if it fails to allocate memory?
Answer: Option A
Explanation: malloc() returns NULL when it cannot allocate the requested amount of memory.
Q12
How is calloc() different from malloc() in terms of parameters?
Answer: Option A
Explanation: calloc() takes number of elements and element size, while malloc() takes total bytes.
Q13
What is dangling pointer?
Answer: Option A
Explanation: Dangling pointer points to memory that has already been freed.
Q14
Which memory allocation function should be used for arrays?
Answer: Option A
Explanation: calloc() is often preferred for arrays as it initializes memory to zero.
Q15
What is the return type of malloc()?
Answer: Option A
Explanation: malloc() returns void* which can be cast to any pointer type.
Q16
What happens if you free the same memory twice?
Answer: Option A
Explanation: Double freeing causes undefined behavior, often program crash.
Q17
Which function allocates memory and initializes it to zero?
Answer: Option A
Explanation: calloc() both allocates and initializes memory to zero.
Q18
What is the main advantage of dynamic memory allocation?
Answer: Option A
Explanation: Dynamic allocation allows memory size to be determined at runtime.
Q19
Where is dynamically allocated memory stored?
Answer: Option A
Explanation: Dynamic memory is allocated from the heap segment.
Q20
What should you always check after calling malloc()?
Answer: Option A
Explanation: Always check if malloc() returned NULL indicating allocation failure.