WorksheetsStack Data Structure Quiz
Total questions: 10
Worksheet time: 5mins
Which of the following is the correct way to declare a stack in C using an array?
int stack[];
stack[100];
int stack[100];
int[100] stack
What is the time complexity of the push operation in a stack implemented using an array?
O(1)
O(n)
O(log n)
O(n²)
In a stack, which operation is used to remove an element?
insert()
delete()
enqueue()
pop()
What happens if we try to pop from an empty stack?
Underflow
Overflow
Compilation error
Segmentation fault only
What is the output of the following C code?
#include <stdio.h>
#define SIZE 5
int main() {
int stack[SIZE] = {0}, top = -1;
top++;
stack[top] = 10;
printf("%d", stack[top]);
return 0;
}
0
10
-1
Compilation error
Which data structure is used in function call management in C?
Queue
Tree
Stack
Heap
How can a stack be implemented in C?
Using arrays
Using linked list
Both A and B
None of the above
What is the default top value in an empty stack using array implementation in C?
0
-1
1
NULL
Which of the following is not a valid stack operation?
push()
pop()
peek()
insertAtBottom()
What does the following C function do?
int peek(int stack[], int top) {
return stack[top];
}
Inserts an element
Deletes the top element
Returns top element without removing it
Checks if stack is empty
