Font size
WorksheetsMemory Allocations in C (Static Memory Allocation)
Total questions: 99
Worksheet time: 50mins
What are the two types of memory allocations possible in C?
(a) Static memory allocation (Compile-time allocation using arrays) (b) Dynamic memory allocation (Run-time allocation using pointers)
(a) Manual memory allocation (User-defined allocation) (b) Automatic memory allocation (System-defined allocation)
(a) Temporary memory allocation (Short-term allocation) (b) Permanent memory allocation (Long-term allocation)
(a) Sequential memory allocation (Ordered allocation) (b) Random memory allocation (Unordered allocation)
In static memory allocation, when is the required amount of memory allocated to the program elements?
At the start of the program
At the end of the program
During program execution
After program termination
If you declare an array of five elements in C and try to read ten elements from it, what will happen?
The program will give an error
Only the first five values will be accessible
The extra elements will be accessible
The program will crash
What is one problem with static memory allocation in C?
If you store less number of elements than the number of elements for which you have declared memory, then the rest of the memory will be wasted.
It allows dynamic resizing of arrays at runtime.
It automatically frees unused memory blocks.
It prevents memory fragmentation completely.
In static memory allocation, the memory allocated to a variable is fixed and determined by the compiler at compile time.
True
False
What is the main advantage of dynamic or run-time memory allocation in programming?
It allows memory to be allocated statically
It allows memory to be allocated as needed at run-time
It reduces the flexibility for programmers
It is only used for static arrays
Which function is used in C to allocate a block of memory in bytes at run-time?
calloc()
malloc()
free()
realloc()
Fill in the blank: The syntax for using malloc to allocate memory is _________.
malloc (number of elements * size of each element);
malloc[number of elements * size of each element];
malloc{number of elements * size of each element};
malloc
The malloc() function returns a pointer to the first block of allocated memory, and if it fails, it returns NULL.
True
False
In the statement 'int *ptr; ptr = (int *) malloc (10 * sizeof(int));', how many bytes of memory are allocated?
20 bytes
10 bytes
40 bytes
4 bytes
What is the purpose of type casting in the statement 'ptr_var = (type_cast *) malloc (size);'?
To convert the returned pointer (of type void) to the required data type.
To allocate memory for a variable.
To initialize the pointer variable.
To free the allocated memory.
Consider the following code: char *ptr; ptr = (char *) malloc (10 * sizeof(char)); How many elements of type char are being allocated?
10 elements
1 element
5 elements
20 elements
What is the correct syntax to allocate memory for a struct student in C using malloc?
A) st_ptr = malloc(sizeof(struct student));
B) st_ptr = (struct student *) malloc(sizeof(struct student));
C) st_ptr = (struct student *) malloc(struct student);
D) st_ptr = malloc(struct student);
Fill in the blank: After executing the statement st_ptr = (struct student *) malloc(sizeof(struct student));, a contiguous block of memory of size ____ bytes is allocated to st_ptr.
36
24
48
12
What does the malloc() function return if the requested memory cannot be allocated by the system RAM? Choose the correct option.
0
NULL
-1
1
Fill in the blank: The free() function is used to _______ the previously allocated memory using malloc() functions.
de-allocate
allocate
initialize
copy
What is the syntax of the free function in C?
free(ptr_var);
free(ptr);
free(var);
free(memory);
Fill in the blank: Arrays are called ______ data structures because their sizes are predetermined and memory is reserved before processing.
static
dynamic
linked
sequential
Explain one advantage of using linked lists (dynamic data structures) over arrays (static data structures) as described in the passage.
Linked lists allow easy insertion and deletion of elements without shifting other elements.
Linked lists use less memory than arrays for all types of data.
Arrays are always faster than linked lists for searching elements.
Arrays can grow and shrink in size more easily than linked lists.
What is a linked list?
A linear collection of data elements, called node pointing to the next nodes by means of pointers.
A collection of arrays.
A type of tree structure.
A single data element.
What is the info value stored in Node-2?
20
10
30
40
Which of the following is NOT a basic operation on linked lists?
A) Creation
B) Insertion
C) Multiplication
D) Deletion
Insertion in a linked list can be performed at which of the following positions?
At the beginning
At the end
At a specified position
All of the above
Fill in the blank: If the list itself is empty, then the new node is inserted as a ______ node.
first
last
middle
head
Deletion in a linked list can be performed from the beginning, end, or specified position.
True
False
Forward traversing in a linked list refers to:
Visiting each node from the head to the tail.
Visiting each node from the tail to the head.
Skipping alternate nodes in the list.
Reversing the order of nodes in the list.
Reverse traversing in a linked list refers to:
Visiting the nodes from the last node to the first node.
Visiting the nodes from the first node to the last node.
Deleting nodes from the end of the list.
Inserting nodes at the beginning of the list.
Which of the following is NOT a type of linked list?
Singly linked list
Doubly linked list
Circular linked list
Binary linked list
Fill in the blank: A ________ linked list is also called a linear linked list.
singly
doubly
circular
header
In a singly linked list, you can access the predecessor node directly from the current node.
True
False
What is the link value of Node-3 in the singly linked list diagram?
0
1
2
3
The main advantage of a doubly linked list over a singly linked list is:
It allows traversal in both directions.
It uses less memory than a singly linked list.
It is easier to implement than a singly linked list.
It does not require pointers.
What is the info value stored in Node-2?
2
4
6
1000
What is the address stored in the link field of Node-3?
1000
2000
3000
0
Fill in the blank: A circular linked list is one which has no _______ and no _______.
beginning, end
head, tail
nodes, links
data, pointer
A singly linked list can be made circular by:
Linking the last node to the first node
Linking the first node to the last node
Removing the head node
Linking every node to itself
What is a circular doubly linked list?
A list with only successor pointers
A list with only predecessor pointers
A list with both successor and predecessor pointers in circular manner
A list with random pointers
What is the INFO value of Node-2?
2
4
6
8
Refer to Fig. (4). A Circular Doubly Linked List. Fill in the blank: The address of the right pointer of Node-3 is _______.
1000
2000
3000
4000
Which step in the algorithm to insert a node at the beginning of a singly linked list sets the LINK of the new node?
Step 2
Step 3
Step 4
Step 5
Fill in the blank: Before inserting the first node in the singly linked list, START = _______.
NULL
0
START
FIRST
What is the purpose of the 'insert_beg()' function in the context of singly linked lists?
To delete a node from the beginning
To insert a node at the beginning
To search for a node
To reverse the linked list
Function to insert node at the beginning of the singly linked list: In the 'insert_beg()' function, which statement allocates memory for the new node?
A) ptr=(list *)malloc(sizeof(list));
B) ptr->info=num;
C) start=ptr;
D) scanf("%d,&num);
What is the initial value of START before inserting the first node in the singly linked list? Fill in the blank: START = _____.
NULL
0
START
1
Algorithm to insert node at the end of the singly linked list: Which step in the algorithm sets the INFO part of the new node?
Step 1
Step 2
Step 3
Step 4
What does the TEMP pointer do in the algorithm for inserting a node at the end of the singly linked list?
It traverses the list to find the last node.
It stores the value to be inserted.
It points to the head of the list.
It deletes the last node.
Function to insert node at the beginning of the singly linked list: True or False: The statement 'ptr->link=start;' in the 'insert_beg()' function sets the new node's link to point to the previous first node.
True
False
Algorithm to insert node at the end of the singly linked list: Fill in the blank: The link part of the new node is set to _____ in Step 4.
NULL
HEAD
PREV
START
What is the purpose of the 'temp' pointer in the function to insert a node at the end of a singly linked list?
To store the value to be inserted
To traverse the list to the last node
To allocate memory for the new node
To delete a node
In the function to insert a node at the end of a singly linked list, the statement 'ptr->link = ____;' sets the link of the new node to
NULL
head
ptr
temp
Algorithm to insert node at a specific location in the singly linked list: According to the algorithm, what happens if the location LOC is greater than the total number of nodes in the list?
The node is inserted at the end
The node is inserted at the beginning
The node cannot be inserted and an error message is shown
The node is inserted at the specified location anyway
Before inserting the first node in the singly linked list, the value of START is set to ____ and F is set to 0.
NULL
0
1
START
What is the purpose of Step 3 in the algorithm for inserting a node in a singly linked list?
To delete a node
To allocate memory for the new node
To read the value to be inserted
To set the link of the new node
What is the purpose of the 'insert_spe' function in the given code?
To insert a special element into a data structure.
To delete a specific element from a list.
To update the value of a variable.
To sort the elements in an array.
In the code, which statement is used to allocate memory for the new node?
ptr = (list *)malloc(sizeof(list));
temp = start;
ptr->info = num;
temp = temp->link;
Fill in the blank: In the algorithm, if LOC is equal to 1, the new node's LINK is set to _______.
START
NULL
END
HEAD
What is the first step in the algorithm to delete a node from the beginning of a singly linked list?
Check if START is NULL, then write "List is empty" and return.
Move the START pointer to the next node.
Delete the last node in the list.
Insert a new node at the beginning.
Why is it important to deallocate memory of the node at the beginning of the singly linked list?
To prevent memory leaks
To increase the size of the linked list
To make the node accessible again
To speed up the insertion process
What does the function delete_beg() do in a singly linked list?
It deletes the node at the beginning of the singly linked list and frees its memory.
It deletes the node at the end of the singly linked list and frees its memory.
It inserts a node at the beginning of the singly linked list.
It reverses the singly linked list.
In the function delete_beg(), what is printed if the list is empty?
The deleted element from the beginning of singly linked list is : %d
List is empty
Memory deallocated
Node deleted
In the algorithm to delete a node from the beginning of a singly linked list, which pointer is used to deallocate memory?
A) START
B) PTR
C) LINK
D) INFO
What does the algorithm do if the list is empty?
It writes 'List is empty' and returns.
It sorts the list and continues.
It adds a default value to the list.
It throws an error and stops.
What is the value of START after deleting the only node in the list?
NULL
0
1
START
What does NUM represent in the algorithm?
NUM represents the information part of the deleted node.
NUM represents the address of the next node.
NUM represents the total number of nodes in the list.
NUM represents the position of the head node.
Function to delete node from the end of the singly linked list void delete_end() What is printed if the list is empty?
A) List is empty
B) Deleted element from the end
C) NULL
D) Error
Function to delete node from the end of the singly linked list Which pointer is used to traverse the list to the last node?
A) start
B) temp
C) ptr
D) num
What does PTR represent in the algorithm to delete a node from a specific location in the singly linked list?
The address of the first node
The structure pointer which deallocates memory of the node
The element to be deleted
The link to the next node
In the algorithm to delete a node from a specific location in the singly linked list, what is the first step if START is NULL?
Set PTR := START
Write: 'List is empty' and return
Read the location LOC
Set NUM := PTR->INFO
Fill in the blank: In the algorithm, TEMP is a structure pointer to modify the ______ part of the previous node.
LINK
DATA
HEAD
TAIL
Which step in the algorithm reads the location LOC from where you want to delete the node?
Step 1
Step 2
Step 3
Step 4
In the algorithm, if PTR is NULL during the loop, it means the total nodes in the list are less than the given position.
True
False
What is written in Step 6 of the algorithm to delete a node from a specific location in the singly linked list?
'List is empty' and return
'Total nodes in the list are less than this position'
'Deleted element from the singly linked list :', NUM
'So node cannot be deleted' and return
Fill in the blank: Step 8 of the algorithm is to ______.
Exit
Continue
Repeat
Start
What is the purpose of the function 'delete_spe()' in the given code snippet?
To insert a node at a specific location in a singly linked list
To delete a node from a specific location in a singly linked list
To search for a node in a singly linked list
To reverse a singly linked list
Fill in the blank: In the function 'delete_spe()', if 'start' is NULL, the function prints 'List is empty' and _______.
returns
continues
exits
loops
What happens in the function 'delete_spe()' if the location entered by the user is 1?
The first node in the list is deleted.
The last node in the list is deleted.
No node is deleted.
A new node is added at the first position.
In the function 'delete_spe()', if the entered location is greater than the number of nodes in the list, the function prints 'Total nodes in the list are lesser than this position.' and 'So node cannot be deleted'.
True
False
Fill in the blank: After deleting the node, the function prints 'The deleted element from the singly linked list is : %d', where %d is replaced by _______.
the value of num, which is ptr->info (the deleted node's info)
the address of the deleted node
the total number of nodes in the list
the value of the next node's info
What is the purpose of the 'initialize()' function in the singly linked list program?
To insert a node at the beginning
To set up the initial state of the list
To delete a node
To traverse the list
Which function is used to insert a node at the beginning of the singly linked list?
insert_end()
insert_beg()
insert_spe()
delete_beg()
Fill in the blank: The function used to delete a node from the end of the singly linked list is ________.
delete_end()
delete_start()
insert_end()
insert_start()
Which menu option allows you to traverse the singly linked list?
1
4
7
8
Fill in the blank: The function 'insert_spe()' is used for ________ in the singly linked list.
insertion at a specific location
deletion at the end
searching for a node
reversing the list
What does the 'delete_spe()' function do in the singly linked list program?
Deletes the first node
Deletes the last node
Deletes a node from a specific location
Traverses the list
Which header file is NOT included in the singly linked list program?
A) stdio.h
B) conio.h
C) stdlib.h
D) string.h
What is the purpose of the 'initialize' function in the given code snippet?
To insert a node at the beginning of the singly linked list
To set the start pointer to NULL
To delete a node from the singly linked list
To traverse the singly linked list
Which function is called when the user selects choice 1 in the switch-case menu?
insert_end()
insert_spe()
insert_beg()
delete_beg()
Fill in the blank: In the 'insert_beg' function, the statement 'ptr->link = ____;' links the new node to the existing list.
start
NULL
head
temp
What is the purpose of the function 'insert_end()' in the given code?
To delete a node from the singly linked list
To insert a node at the end of the singly linked list
To search for a node in the singly linked list
To insert a node at the beginning of the singly linked list
What does the following line of code do in the 'insert_end()' function? ptr=(list *)malloc(sizeof(list));
Allocates memory for a new node
Frees memory of a node
Initializes the start pointer
Links two nodes together
What is the purpose of the function 'insert_spe()' in the given code?
To insert a node at the end of the singly linked list
To insert a node at a specific location in the singly linked list
To delete a node from the singly linked list
To reverse the singly linked list
Fill in the blank: In the 'insert_spe()' function, the variable 'loc' represents the ______ where the new node should be inserted.
location
value
pointer
index
What is the purpose of the function 'delete_beg()' in the context of singly linked lists?
To insert a node at the beginning
To delete a node from the beginning
To delete a node from the end
To search for a node
Fill in the blank: The function 'delete_end()' is used to delete a node from the ______ of the singly linked list.
end
beginning
middle
head
What will be printed if 'delete_beg()' is called when the list is empty?
List is empty
0
Segmentation fault
Node deleted
The role of 'ptr' in the 'delete_beg()' function for singly linked lists is:
to point to the first node to be deleted
to store the value of the last node
to count the number of nodes in the list
to insert a new node at the beginning
What is the purpose of the function 'delete_spe()' in the given C code for singly linked lists?
To insert a node at a specific location
To delete a node from a specific location
To search for a node
To display the list
In the given code, what will be printed if 'start' is NULL when 'delete_spe()' is called?
List is empty
Node deleted
Invalid location
No output
Fill in the blank: In the function to delete the last node from a singly linked list, the statement 'temp->link=____;' is used to remove the last node.
NULL
temp
head
0
