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)
Show Answer Report
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);
Show Answer Report
3. Specify the 2 library functions to dynamically allocate memory?
  • malloc() and memalloc()
  • alloc() and memalloc()
  • malloc() and calloc()
  • memalloc() and faralloc()
Show Answer Report
4. Which function is used to allocate memory dynamically in C?
  • malloc()
  • alloc()
  • new()
  • create()
Show Answer Report
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
Show Answer Report
6. Which function is used to free dynamically allocated memory?
  • free()
  • dealloc()
  • release()
  • delete()
Show Answer Report
7. What is the purpose of the realloc() function?
  • Resizes allocated memory
  • Reallocates stack memory
  • Relocates program in memory
  • Reinitializes memory
Show Answer Report
8. What happens if you try to free a NULL pointer?
  • Nothing, it is safe
  • Program crashes
  • Memory leak occurs
  • Undefined behavior
Show Answer Report
9. Which header file is required for dynamic memory allocation functions?
  • stdlib.h
  • stdio.h
  • memory.h
  • alloc.h
Show Answer Report
10. What is memory leak in C?
  • Memory not freed after use
  • Memory allocated too slowly
  • Memory corrupted by virus
  • Memory allocation failure
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test