Peek Top Element of Stack
📖 Scenario: You are building a simple program to manage a stack of books. You want to be able to see the top book on the stack without removing it.
🎯 Goal: Create a stack using an array, set up a variable to track the top, write code to peek at the top element, and print it.
📋 What You'll Learn
Create an integer array called
stack with exactly these values: 10, 20, 30, 40, 50Create an integer variable called
top and set it to 4Create an integer variable called
peek and set it to the top element of the stack using stack[top]Print the value of
peek using printf💡 Why This Matters
🌍 Real World
Stacks are used in many places like undo features in apps, browser history, and managing function calls.
💼 Career
Understanding stack operations like peek is important for software development, debugging, and working with low-level programming.
Progress0 / 4 steps
