wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Stack Data Structure Quiz

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which of the following is the correct way to declare a stack in C using an array?

a)

int stack[];

b)

stack[100];

c)

int stack[100];

d)

int[100] stack

2.

What is the time complexity of the push operation in a stack implemented using an array?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

3.

In a stack, which operation is used to remove an element?

a)

insert()

b)

delete()

c)

enqueue()

d)

pop()

4.

What happens if we try to pop from an empty stack?

a)

Underflow

b)

Overflow

c)

Compilation error

d)

Segmentation fault only

5.

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;

}

a)

0

b)

10

c)

-1

d)

Compilation error

6.

Which data structure is used in function call management in C?

a)

Queue

b)

Tree

c)

Stack

d)

Heap

7.

How can a stack be implemented in C?

a)

Using arrays

b)

Using linked list

c)

Both A and B

d)

None of the above

8.

What is the default top value in an empty stack using array implementation in C?

a)

0

b)

-1

c)

1

d)

NULL

9.

Which of the following is not a valid stack operation?

a)

push()

b)

pop()

c)

peek()

d)

insertAtBottom()

10.

What does the following C function do?
int peek(int stack[], int top) {

return stack[top];

}

a)

Inserts an element

b)

Deletes the top element

c)

Returns top element without removing it

d)

Checks if stack is empty