C- Memory Allocation Questions and Answers
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