- 01Getting Started
- 02Your First Output (printf)
- 03Working with Variables
- 04Conditionals (if statements)
- 05Loops (for statements)
- 06Writing a Function
- 07Working with Arrays
- 08Loops (while statements)
- 09Working with Structs
- 10Error Handling (Checking a Return Value)
- 11Sorting an Array (Bubble Sort)
- 12Recursive Functions
- 13The String-Handling Standard Library
- 14The switch Statement
- 15The Ternary Operator
- 16Pointer Basics
- 17Writing Comments
- 18Logical Operators (&&, ||, !)
- 19Constants (#define and const)
- 20Splitting Strings (strtok)
- 21Handling NULL Pointers Safely
- 22Searching an Array (Looping with strcmp)
- 23Transforming an Array (map-like Logic)
- 24Two-Dimensional Arrays (Tabular Data)
- 25Custom Errors (Categorizing with Error Codes)
- 26Using Variable-Length Argument Lists (stdarg.h)
- 27Removing Duplicates from an Array (Set-Like Logic)
- 28Checking Correctness with the assert Macro (Your First Step into Testing)
- 29Higher-Order Functions (Passing a Function Pointer as an Argument)
- 30Stacks and Queues (Basic Data Structures)
- 31Type Conversion (Casting) Basics
- 32Intro to Regular Expressions (regex.h)
- 33The Binary Search Algorithm
- 34Building a Caesar Cipher (a Character-Shifting Cipher)
- 35Understanding How Selection Sort Works
- 36Building and Displaying Dates (struct tm)
- 37Writing Multiple Test Cases Together
- 38Speeding Up Calculations with Memoization (Caching)
- 39Normalizing Strings (Stripping Whitespace, Unifying Case)
- 40Shallow Copy vs. Deep Copy
- 41Enum (Enumerated Types) Basics
- 42Flattening an Array
- 43Reversing a String and Checking for Palindromes
- 44Pairing Up Two Arrays (the zip operation)
- 45Rounding Numbers (floor, ceil, round)
- 46Multi-Line Strings (Adjacent String Literal Concatenation)
- 47Functions That Return Multiple Values (Structs)
- 48Finding the GCD and LCM (the Euclidean Algorithm)
- 49Formatting Numbers (Padding Digits, Decimal Places)
- 50Bundling Cleanup Logic with goto
- 51Writing Type-Agnostic Logic with Macros
- 52File Reading and Writing Basics
- 53Generating Random Numbers
- 54Bitwise Operators (AND, OR, XOR, shifts)
- 55Reading Command-Line Arguments
- 56Waiting for a Fixed Amount of Time (sleep)
- 57Watch Out for Floating-Point Rounding Errors
- 58Reading from Standard Input
- 59FizzBuzz (the Classic Practice Problem)
- 60Checking Whether a Number Is Prime
- 61Set Operations with an Array (Intersection, Difference)
- 62Converting Number Bases (Binary, Hex)
- 63Checking Balanced Parentheses (an Application of Stacks)
- 64Checking Whether Two Words Are Anagrams
- 65Checking Whether a Year Is a Leap Year
- 66Converting Temperature (Celsius to Fahrenheit)
- 67Prime Factorization
- 68[Applied] Build a Simple Grade Aggregation Program
Checking Balanced Parentheses (an Application of Stacks)
This lesson covers checking whether parentheses are balanced in C using a stack, so you understand a practical application of the stack data structure. It's for anyone searching "C balanced parentheses stack application."
Using a stack (last in, first out), you can check whether parentheses are balanced by pushing an opening bracket like ( or [ onto the stack, and checking whether it matches the top of the stack every time a closing bracket comes up.
The example builds a stack by combining an array, char stack[100], with an index, top โ pushing when an opening bracket comes up, and checking against the top of the stack when a closing bracket comes up. If the stack is empty once everything's processed, the parentheses are balanced.
A common early mistake is handling several types of brackets at once (parentheses, square brackets, and curly braces mixed together). Simply counting opens and closes isn't enough โ you also need to confirm they're nested in the correct order.
A similar idea is used when a compiler parses syntax too โ a widely applicable way of thinking.
๐งช This site can't compile or run C directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
