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
1. What function should be used to free the memory allocated by calloc() ?
- dealloc();
- malloc(variable_name, 0)
- free();
- memalloc(variable_name, 0)
2. How will you free the memory allocated by the following program? #include<stdio.h> #include<stdlib.h> #define MAXROW 3 #define MAXCOL 4 int main() { int **p, i, j; p = (int **) malloc(MAXROW * sizeof(int*)); return 0; }
- memfree(int p);
- dealloc(p);
- malloc(p, 0);
- free(p);
3. Specify the 2 library functions to dynamically allocate memory?
- malloc() and memalloc()
- alloc() and memalloc()
- malloc() and calloc()
- memalloc() and faralloc()
4. Which function is used to allocate memory dynamically in C?
- malloc()
- alloc()
- new()
- create()
5. What does the calloc() function do differently from malloc()?
- Initializes memory to zero
- Allocates memory on stack
- Automatically frees memory
- Allocates memory for functions
6. Which function is used to free dynamically allocated memory?
- free()
- dealloc()
- release()
- delete()
7. What is the purpose of the realloc() function?
- Resizes allocated memory
- Reallocates stack memory
- Relocates program in memory
- Reinitializes memory
8. What happens if you try to free a NULL pointer?
- Nothing, it is safe
- Program crashes
- Memory leak occurs
- Undefined behavior
9. Which header file is required for dynamic memory allocation functions?
- stdlib.h
- stdio.h
- memory.h
- alloc.h
10. What is memory leak in C?
- Memory not freed after use
- Memory allocated too slowly
- Memory corrupted by virus
- Memory allocation failure