C- Memory Allocation Questions and Answers

Practice Mode
Showing 10 of 28 questions
Q21
What is the syntax for allocating memory for 10 integers using malloc()?
  • A malloc(10 * sizeof(int))
  • B malloc(10, int)
  • C malloc(sizeof(int) * 10)
  • D alloc(10 * int)
Answer: Option A
Explanation: malloc(10 * sizeof(int)) allocates memory for 10 integers.
Q22
Which function can change the size of allocated memory block?
  • A realloc()
  • B malloc()
  • C calloc()
  • D free()
Answer: Option A
Explanation: realloc() can resize previously allocated memory block.
Q23
What does "stack overflow" refer to?
  • A Exhaustion of stack memory
  • B Heap memory full
  • C Too many malloc calls
  • D Memory fragmentation
Answer: Option A
Explanation: Stack overflow occurs when stack memory is exhausted due to deep recursion or large local variables.
Q24
What is memory fragmentation?
  • A Non-contiguous free memory blocks
  • B Memory with errors
  • C Memory allocated too slowly
  • D Memory not initialized
Answer: Option A
Explanation: Memory fragmentation occurs when free memory is divided into small, non-contiguous blocks.
Q25
Which is faster: malloc() or calloc()?
  • A malloc()
  • B calloc()
  • C Both are same speed
  • D Depends on system
Answer: Option A
Explanation: malloc() is generally faster as it doesn't initialize memory to zero.
Q26
What is wild pointer?
  • A Uninitialized pointer
  • B Pointer to freed memory
  • C Constant pointer
  • D Pointer to stack
Answer: Option A
Explanation: Wild pointer is uninitialized pointer that points to random memory location.
Q27
How to avoid memory leaks in C?
  • A Free memory and set pointer to NULL
  • B Use only stack memory
  • C Avoid using pointers
  • D Use automatic garbage collection
Answer: Option A
Explanation: Always free allocated memory and set pointer to NULL after freeing.
Q28
What is the purpose of the sizeof operator in malloc()?
  • A Calculate element size in bytes
  • B Count number of elements
  • C Check memory alignment
  • D Verify pointer validity
Answer: Option A
Explanation: sizeof calculates the size in bytes needed for each element.
Questions and Answers for Competitive Exams Various Entrance Test