Memory Management in C

This quiz will test your understanding on the concepts related to memory management in C Programming.

Last Updated :
Discuss
Comments

Question 1

Which of the following functions is used for dynamic memory allocation in C?

  • malloc()

  • alloc()

  • memalloc()

  • memory()

Question 2

What header file is needed to use malloc() and free()?


  • stdio.h


  • stdlib.h

  • malloc.h

  • mem.h

Question 3

Which function deallocates memory previously allocated using malloc()?

  • clear()

  • remove()

  • free()

  • delete()

Question 4

Which of the following allocates memory and also initializes it to zero?

  • malloc()

  • calloc()

  • realloc()

  • memset()

Question 5

What happens if you forget to free memory allocated with malloc()?

  • Compilation error

  • Segmentation fault

  • Memory leak

  • Pointer corruption

Question 6

What is the key difference between malloc() and calloc()?


  • malloc() is faster

  • calloc() doesn't require casting

  • malloc() initializes memory to zero


  • calloc() initializes memory to zero

Question 7

What does realloc(ptr, 0) do?

  • Resizes memory to 0 but keeps the pointer valid

  • Same as free(ptr)

  • Creates an error

  • No effect

Question 8

What is returned by malloc() if the allocation fails?

  • 0

  • -1

  • NULL

  • Causes Error.

Question 9

What happens if you free() a pointer that was never dynamically allocated?

  • Nothing

  • Compiler warning

  • Undefined behavior

  • Graceful termination

Question 10

Which scenario is most likely to cause a segmentation fault?

  • Using a variable before declaration

  • Dividing by zero

  • Accessing memory that has been freed


  • Printing NULL

Tags:

There are 20 questions to complete.

Take a part in the ongoing discussion