
Concept Notes: Arrays & Stacks – Basics
🔹 1. What is a Data Structure?
- A Data Structure is a way to organize and store data so it can be used efficiently.
- Examples: Arrays, Stacks, Queues, Linked Lists, Trees, Graphs
🔹 2. Arrays
- An Array is a collection of elements stored in contiguous memory locations.
- All elements must be of the same data type.
int arr[5] = {1, 2, 3, 4, 5};
Key Points:
- Fixed size (declared at compile time)
- Accessed using index: starts from
0
- Efficient for storing multiple values
🔹 3. Stacks
- A Stack is a linear data structure that follows LIFO (Last In First Out).
- Insertion = Push, Deletion = Pop
✅ Operations:
Operation | Description |
---|---|
Push | Add element to top |
Pop | Remove top element |
Peek | View top element |
isEmpty | Check if stack is empty |
📦 Stack Real-Life Example:
- Stack of plates — you remove the top plate first.
// Push operation example
stack[top++] = 10;
// Pop operation example
top--;
MCQs – Day 2: Data Structures – Arrays & Stacks
1️⃣ Which of the following is correct syntax for declaring an array in C?
A) int arr();
B) int arr[] = ();
C) int arr[5];
D) array arr[5];
2️⃣ What is the index of the first element in an array?
A) 0
B) 1
C) -1
D) None of these
3️⃣ Which operation adds an element to a stack?
A) insert()
B) append()
C) push()
D) add()
4️⃣ In which order does a stack operate?
A) FIFO
B) FILO
C) LIFO
D) Random
5️⃣ What happens when you try to pop from an empty stack?
A) Push happens
B) Stack is resized
C) Stack Overflow
D) Stack Underflow
6️⃣ How to access the third element in int arr[5]
?
A) arr(3)
B) arr[2]
C) arr[3]
D) arr[1]
7️⃣ What is the output of:
int arr[3] = {10, 20, 30};
printf("%d", arr[1]);
A) 10
B) 20
C) 30
D) Garbage value
8️⃣ What is a correct feature of stack?
A) Random access
B) First element removal
C) Constant size
D) Last element inserted is removed first
9️⃣ Which keyword is used to define a constant array size in C?
A) const
B) #define
C) fixed
D) size
🔟 Which of the following is not an application of stack?
A) Function call management
B) Undo feature in editors
C) Infix to postfix conversion
D) Binary search
✅ Answer Key
Q.No | Answer |
---|---|
1 | C |
2 | A |
3 | C |
4 | C |
5 | D |
6 | B |
7 | B |
8 | D |
9 | B |
10 | D |
🧠 Explanations
- Q1: Correct array declaration in C:
int arr[5];
- Q2: Array indexing starts from 0
- Q3: Stack insertion is called Push
- Q4: Stack = Last In, First Out (LIFO)
- Q5: Removing from empty stack = Underflow
- Q6:
arr[2]
= third element - Q7:
arr[1]
= 20 - Q8: Stack always removes last inserted item
- Q9: Constant values in C often defined using
#define SIZE 10
- Q10: Binary search is done on sorted arrays, not stacks
📥 Download PDF of Notes + MCQs
📌 Available at 9 AM in Telegram Group:
👉 @LearnNewThingsHub
💬 Comment Task for Learners
🗣 Which confuses you more – Arrays indexing or Stack Push/Pop logic?
Tell us in comments — we’ll create a video on it!