Loops in C: while, for, and do-while Statements

Loops let a program repeat a block of code without writing it out multiple times. C provides three looping constructs — while, for, and do-while — each suited to slightly different situations. This is Post 1 of the Unit II series, following Unit I’s coverage of decision making. The while Loop Checks its condition before … Read more

Decision Making in C: if, if-else, and switch Statements

Every interesting program needs to make decisions — do this if a condition holds, do something else otherwise. C provides two main tools for this: the if family of statements and the switch statement. This is Post 5, closing out the Unit I series on C fundamentals. The if Statement if (condition) { // executes … Read more

Operators, Expressions, Precedence, Associativity, and Type Conversion in C

C provides a rich set of operators for arithmetic, comparison, logic, and more. But operators become genuinely useful only once you understand how they combine into expressions, and crucially, in what order they’re evaluated when several appear together. This is Post 4 of the Unit I series. Categories of Operators 1. Arithmetic Operators + addition … Read more

Variables, Constants, and Input/Output Statements in C

Now that we know the basic data types (from Post 2), it’s time to put them to work: declaring variables to hold changing data, constants for values that must never change, and reading/printing data with C’s input/output statements. This is Post 3 of the Unit I series. Variables A variable is a named location in … Read more

Structure of a C Program, Identifiers, and Basic Data Types

Every C program, no matter how large, is built from the same basic skeleton. Once you recognize this structure, reading (and writing) any C program becomes far less intimidating. This is Post 2 of the Unit I series — Post 1 covered algorithms and flowcharts. The Structure of a C Program #include <stdio.h> // 1. … Read more

Functions in C Part 3: Storage Classes, Function Pointers, and Multi-File Programs

In Part 1 we covered the fundamentals, and in Part 2 we covered parameter passing and recursion. In this final part, we look at three more advanced (but very practical) topics: storage classes, function pointers, and how real projects organize functions across multiple files. Storage Classes A storage class in C controls two things about … Read more

Functions in C Part 2: Call by Value, Call by Reference, Scope, and Recursion

In Part 1, we covered what functions are and how to declare, define, and call them. In this post, we go deep into how values actually travel into and out of functions, what pointers are and how they enable call by reference, where variables “live” (scope), and one of the most important ideas in programming: … Read more

Functions in C Part 1: The Basics — Declaration, Definition, and Calling

A function is a self-contained block of code that performs a specific task. Instead of writing the same logic again and again, you write it once inside a function and call that function wherever you need that task done. This is the single most important idea for writing programs that are longer than a few … Read more

Search for an Element in a 2-D Array in C

This program searches for a given element in a 2-D array and displays its position (row and column) if found. C Program #include <stdio.h> int main() { int a[10][10], m, n, i, j, key, found = 0; printf(“Enter number of rows (m) and columns (n): “); scanf(“%d %d”, &m, &n); printf(“Enter elements of the matrix:\n”); … Read more