C- Memory Allocation Questions and Answers
C Memory Allocation questions with answers are vital for mastering dynamic memory management in C programming. These programming questions and answers help learners understand malloc(), calloc(), realloc(), and free() functions in detail. Practicing C programming MCQ or programming interview questions with answers builds a strong foundation for coding interviews and placement exams at companies like TCS, Infosys, and Accenture. Proper memory allocation ensures efficient use of system resources and prevents memory leaks, which are common pitfalls for beginners. Through regular practice, students can develop confidence in handling memory dynamically during programming test practice sessions or while preparing for technical rounds.
C- Memory Allocation
Showing 10 of
28 questions
11. What does malloc() return if it fails to allocate memory?
- NULL
- 0
- -1
- Garbage value
12. How is calloc() different from malloc() in terms of parameters?
- Takes number of elements and element size
- Takes only total size
- Takes pointer to existing memory
- Takes alignment parameter
13. What is dangling pointer?
- Pointer to freed memory
- Uninitialized pointer
- Pointer to stack memory
- Pointer to constant data
14. Which memory allocation function should be used for arrays?
- calloc()
- malloc()
- realloc()
- free()
16. What happens if you free the same memory twice?
- Undefined behavior
- Memory leak
- Safe operation
- Automatic reallocation
17. Which function allocates memory and initializes it to zero?
- calloc()
- malloc()
- realloc()
- alloc()
18. What is the main advantage of dynamic memory allocation?
- Memory size determined at runtime
- Faster execution
- Automatic memory management
- No need to free memory
19. Where is dynamically allocated memory stored?
- Heap
- Stack
- Data segment
- Code segment
20. What should you always check after calling malloc()?
- If return value is NULL
- If memory is initialized
- If pointer is aligned
- If enough stack space