Skip to main content

Data Structures MCQs with Answers

Practice important Data Structures MCQs with answers and explanations.

Chapter: 3
Q41:
What does a '0' in the pointer part of a linked list node signify?
A. It's the first node
B. It's the middle node
C. It's pointing to another node
D. It's the last node
Correct Answer: D
Chapter: 3
Q42:
What is the main function of the add() method in the linked list?
A. To delete a node
B. To find a node
C. To create and insert a new node
D. To sort nodes
Correct Answer: C
Chapter: 3
Q43:
How is a new node created in C++ for a linked list?
A. Node* newNode = new Node();
B. int* newNode = new int();
C. Node newNode;
D. newNode = new Node(9);
Correct Answer: A
Chapter: 3
Q44:
What does the get() method in the Node class return?
A. Memory address of the node
B. Value stored in the node
C. Memory address of the next node
D. Size of the linked list
Correct Answer: B
Chapter: 3
Q45:
What does the set() method in the Node class do?
A. Sets the pointer of the next node
B. Sets the pointer of the previous node
C. Sets the data value of the node
D. Initializes the linked list
Correct Answer: C
Chapter: 3
Q46:
Which pointer is used to connect nodes in a linked list?
A. Data
B. Current
C. Next
D. Head
Correct Answer: C
Chapter: 3
Q47:
What type of memory allocation does the new operator perform?
A. Static memory
B. Dynamic memory
C. Automatic memory
D. Stack memory
Correct Answer: B
Chapter: 3
Q48:
What does the next() method in the List class do?
A. Moves to the previous node
B. Deletes the current node
C. Moves to the next node
D. Retrieves the value of the node
Correct Answer: C
Chapter: 3
Q49:
What is the first step when adding a new node to a linked list?
A. Assigning it to NULL
B. Pointing its next pointer to the next node
C. Deleting the existing node
D. Setting it as the head node
Correct Answer: B
Chapter: 3
Q50:
In the List class constructor, what does the headNode->setNext(NULL); statement do?
A. Initializes the head node
B. Sets the next node to NULL
C. Creates a new node
D. Deletes the head node
Correct Answer: B
Chapter: 3
Q51:
What happens to the size variable when a new node is added to the linked list?
A. It remains unchanged
B. It increases by 1
C. It decreases by 1
D. It is reset to 0
Correct Answer: B
Chapter: 3
Q52:
What is the correct order of pointers after inserting a new node in a linked list?
A. newNode -> currentNode -> nextNode
B. currentNode -> newNode -> nextNode
C. newNode -> nextNode -> currentNode
D. currentNode -> nextNode -> newNode
Correct Answer: B
Chapter: 3
Q53:
What is the purpose of the lastCurrentNode pointer in the add() method?
A. To track the next node
B. To track the previous node
C. To track the first node
D. To track the last node
Correct Answer: B
Chapter: 3
Q54:
In the example program, what does traverse(List list); do?
A. Adds a new node
B. Removes a node
C. Iterates through the list
D. Sorts the list
Correct Answer: C
Chapter: 3
Q55:
What does friend keyword in the List class declaration signify?
A. Allows function to access private members
B. Restricts function from accessing members
C. Limits the scope of the function
D. Enhances security of the class
Correct Answer: A
Chapter: 3
Q56:
How is memory dynamically allocated for an array in C++?
A. int* arr = new int[10];
B. int arr[10];
C. int* arr = malloc(10 * sizeof(int));
D. int arr[10] = new int;
Correct Answer: A
Chapter: 3
Q57:
What does headNode->setNext(newNode); do when adding a new node to the list?
A. Deletes the next node
B. Assigns the head node
C. Points head node to the new node
D. Initializes the list
Correct Answer: C
Chapter: 3
Q58:
What is the purpose of the getNext() method in the Node class?
A. Returns the next node's value
B. Returns the next node's pointer
C. Returns the previous node's pointer
D. Returns the previous node's value
Correct Answer: B
Chapter: 3
Q59:
What is the function of the add(int addObject) method in the List class?
A. Removes a node
B. Retrieves a node
C. Creates and inserts a new node
D. Sorts the nodes
Correct Answer: C
Chapter: 3
Q60:
What is the output of the get() method if the currentNode is NULL?
A. Returns 0
B. Throws an error
C. Returns NULL
D. Does nothing
Correct Answer: D

Test Your Knowledge

Take a timed quiz on Data Structures

🚀 Start Quiz Now