C Questions and Answers – Static vs Dynamic Memory Allocation

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Static vs Dynamic Memory Allocation”.

Pre-requisite for Static vs Dynamic Memory Allocation MCQ set: Video Tutorial on C Data Types – Memory Allocation.

1. Local variables are stored in an area called ___________
a) Heap
b) Permanent storage area
c) Free memory
d) Stack
View Answer

Answer: d
Explanation: Local variables are stored in an area called stack. Global variables, static variables and program instructions are stored in the permanent storage area. The memory space between these two regions is known a heap.

2. The size of both stack and heap remains the same during run time.
a) True
b) False
View Answer

Answer: b
Explanation: Memory can be allocated or de-allocated during the run time in the heap region. Memory bindings (allocation and de-allocation) are established and destroyed during the execution of the program. Hence we can see that the size of heap does not remain same during run time. However, the size of stack remains the same.
advertisement
advertisement

3. Choose the statement which is incorrect with respect to dynamic memory allocation.
a) Memory is allocated in a less structured area of memory, known as heap
b) Used for unpredictable memory requirements
c) Execution of the program is faster than that of static memory allocation
d) Allocated memory can be changed during the run time of the program based on the requirement of the program
View Answer

Answer: c
Explanation: Execution of the program using dynamic memory allocation is slower than that using static memory allocation. This is because in dynamic memory allocation, the memory has to be allocated during run time. This slows down the execution of the program.

4. Which of the following header files must necessarily be included to use dynamic memory allocation functions?
a) stdlib.h
b) stdio.h
c) memory.h
d) dos.h
View Answer

Answer: a
Explanation: stdlib.h is a header file which stands for the standard library. It consists of the declaration for dynamic memory allocation functions such as malloc(), calloc(), realloc() and free.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

5. The type of linked list in which the node does not contain any pointer or reference to the previous node is _____________
a) Circularly singly linked list
b) Singly linked list
c) Circular doubly linked list
d) Doubly linked list
View Answer

Answer: b
Explanation: A singly linked list is one in which each node has two fields, namely data field and pointer field. Data field stores the data and the pointer field points to the address of the next node.

6. Which of the following is an example for non linear data type?
a) Tree
b) Array
c) Linked list
d) Queue
View Answer

Answer: a
Explanation: A data structure is said to be linear if its elements form a sequence or a linear list. For example array, linked list, queue, stack etc. Elements in a non linear data structure do not form a sequence. For example Trees, graphs etc.
advertisement

7. Queue data structure works on the principle of ____________
a) Last In First Out (LIF0)
b) First In Last Out (FILO)
c) First In First Out (FIFO)
d) Last In Last Out (LILO)
View Answer

Answer: c
Explanation: Queue is a linear data structure which works on the principle of first in first out. This means that the first element to be inserted in a queue will be the first one to be removed.

8. Which of the following is an example of static memory allocation?
a) Linked list
b) Stack
c) Queue
d) Array
View Answer

Answer: d
Explanation: Array is an example of static memory allocation whereas linked list, queue and stack are examples for dynamic memory allocation.
advertisement

9. Array is preferred over linked list for the implementation of ________
a) Radix sort
b) Insertion sort
c) Binary search
d) Polynomial evaluation
View Answer

Answer: c
Explanation: When we try to implement binary search using linked list, the traversal steps per element increases in order to find the middle element. Thus, this process is slow and inefficient. This process is much faster using an array, hence it is preferable to use an array for the implementation of binary search.

10. The advantage of using linked lists over arrays is that ________
a) Linked list is an example of linear data structure
b) Insertion and deletion of an element can be done at any position in a linked list
c) Linked list can be used to store a collection of homogenous and heterogeneous data types
d) The size of a linked list is fixed
View Answer

Answer: b
Explanation: Insertion and deletion in a linked list can be done at any position. On the other hand, in an array, to insert an element at a specific position, the rest of the elements have to be moved one position to the left and to delete an element, all the elements after the deleted element have to be moved one position to the right.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.