C- Memory Allocation Questions and Answers
Practice ModeShowing 10 of 28 questions
Q1
What function should be used to free the memory allocated by calloc() ?
Answer: Option C
Q2
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;
}
Answer: Option D
Q3
Specify the 2 library functions to dynamically allocate memory?
Answer: Option C
Q4
Which function is used to allocate memory dynamically in C?
Answer: Option A
Explanation: malloc() is used to allocate memory dynamically at runtime.
Q5
What does the calloc() function do differently from malloc()?
Answer: Option A
Explanation: calloc() initializes allocated memory to zero, while malloc() leaves it uninitialized.
Q6
Which function is used to free dynamically allocated memory?
Answer: Option A
Explanation: free() is used to deallocate memory that was previously allocated by malloc(), calloc(), or realloc().
Q7
What is the purpose of the realloc() function?
Answer: Option A
Explanation: realloc() is used to resize previously allocated memory block, either expanding or shrinking it.
Q8
What happens if you try to free a NULL pointer?
Answer: Option A
Explanation: free(NULL) is safe and does nothing according to C standard.
Q9
Which header file is required for dynamic memory allocation functions?
Answer: Option A
Explanation: stdlib.h contains declarations for malloc(), calloc(), realloc(), and free().
Q10
What is memory leak in C?
Answer: Option A
Explanation: Memory leak occurs when allocated memory is not freed, causing gradual memory consumption.