Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an array of 5 integers.
DSA C
int numbers[[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero as size which creates an empty array.
Forgetting to specify the size.
✗ Incorrect
The array size must be specified as 5 to hold 5 integers.
2fill in blank
mediumComplete the code to create a new node in a linked list.
DSA C
struct Node* newNode = (struct Node*) malloc(sizeof([1])); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sizeof(int) which is too small.
Using sizeof(struct) which is invalid.
✗ Incorrect
We allocate memory for a Node structure, so sizeof(Node) is needed.
3fill in blank
hardFix the error in the code to correctly insert a node at the beginning of a linked list.
DSA C
newNode->next = [1];
head = newNode; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to newNode causes a cycle.
Setting next to NULL loses the rest of the list.
✗ Incorrect
The new node's next should point to the current head before updating head.
4fill in blank
hardFill both blanks to complete the code that prints all elements of an integer array.
DSA C
for(int i = 0; i [1] n; i[2]) { printf("%d ", arr[i]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes out-of-bounds access.
Using -- causes infinite loop.
✗ Incorrect
The loop runs while i is less than n and increments i each time.
5fill in blank
hardFill all three blanks to complete the code that creates a linked list node and sets its data and next pointer.
DSA C
struct Node* node = (struct Node*) malloc(sizeof([1])); node->data = [2]; node->next = [3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sizeof(int) instead of Node.
Forgetting to set next to NULL.
✗ Incorrect
Allocate memory for Node, assign data from value, and set next to NULL for end of list.
