C is a powerful general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972 and known for its efficiency and flexibility.
It is a very popular language, despite being old. The main reason for its popularity is because it is a fundamental language in the field of computer science.
Why C ?
- Its one of the foundational programming languages used in the development of compilers, operating systems, and embedded systems where speed and efficiency matter.
- It is considered the best language to start because it provides a strong understanding of fundamental coding concepts like data types, variables, loops, and functions.
- C is very fast, compared to other programming languages, like Java and Python
- C is very versatile; it can be used in both applications and technologies
A Program to start with …
int main() //main function
{
int x = 5, y = 10; //declaring varibles
printf("%d", x + y); //outputs 15
return 0;
}
#include <stdio.h>
is a header file library that lets us work with input and output functions, such as printf().
Header files add functionality to C programs.
main()
is called a function. Any code inside its curly brackets {}
will be executed.
printf()
is a function used to output/print text to the screen.
Note that: Every C statement ends with a semicolon
;
The body of
int main()
could also been written as:int main(){printf("Hello World!");return 0;}
The compiler ignores white spaces. However, multiple lines makes the code more readable.
Comments — // This is a single line comment, Multi-line comments start with
/*
and ends with*/
.Any text between
/*
and*/
will be ignored by the compiler.
Character Set In C
A character set is a collection of all characters (like letters, digits, symbols, etc.) that can be used in code. Two types — Source Character Set & Execution Character Set. They’re the fundamental building blocks for creating programs.
Source Character Set — set of characters that can appear in the source code of your C program (i.e., the text you write in your .c
files). This includes the basic C character set (letters, digits, and special characters).
- Alphabets: These represent both uppercase and lowercase English letters. For example, ‘A’ to ‘Z’ and ‘a’ to ‘z’.
- Digits: These represent numeric characters. For example, ‘0’ to ‘9’.
- Special Characters: These include various special characters used in programming and text processing. Some common special characters include:
- Arithmetic Operators: +, -, *, /, %
- Relational Operators: <, >, ==, !=, <=, >=
- Logical Operators: &&, ||, !
- Punctuation: ;, :, ,, ., ?, !
- Brackets and Parentheses: (, ), [, ], {, }
- Quotes: ‘, “
- Backslash: \
- Ampersand: &
- Dollar Sign: $
- Hash or Pound Sign: #
Execution Character Set — set of characters that are used when your C program is running. This is relevant for string literals (text enclosed in double quotes "
) and character constants (text enclosed in single quotes ''
) within your program.
In Execution Character Set, C program understands the characters and uses while it is running.
- Escape Sequences: These are special sequences of characters in the source code that are used to represent characters that might be difficult or impossible to type directly or that have a special meaning to the compiler. Common escape sequences in C include:
\n
(newline),\t
(horizontal tab),\b
(backspace) and more. - Control Characters: These are non-printing characters that perform specific actions when encountered, especially in output streams. Examples include: Newline (
\n
): Moves the cursor to the beginning of the next line, Tab (\t
): Moves the cursor to the next horizontal tab stop, Backspace (\b
): Moves the cursor one position backward and more.
NOTE: the classification of “control characters” and “escape sequences” falls primarily under how characters are represented and interpreted, especially within the context of the execution character set and string/character literals, rather than being a direct subtype of the execution character set itself in the same way that alphabets, digits, and special characters form the source character set.
Constants, Identifiers, Keywords, Basic Data types, Variables
In programming, a variable is a container (storage area) to hold data. To indicate the storage area, each variable should be given a unique name (identifier).
In C programming, identifiers are the names used to identify variables, functions, arrays, structures, or any other user-defined items. It is a name that uniquely identifies a program element and can be used to refer to it later in the program.
To create a variable, specify the type and assign it a value.
In C, there are different types of variables (defined with different keywords), for example:
- int - stores integers (whole numbers), without decimals, such as
123
or-123
- float - stores floating point numbers, with decimals, such as
19.99
or-19.99
- char - stores single characters, such as
'a'
or'B'
. Characters are surrounded by single quotes - double — store decimal numbers (numbers with floating point values) with double precision. It can easily accommodate about 16 to 17 digits after or before a decimal point.
We also have — void, derived, user defined data types.
Variable names are just the symbolic representation of a memory location. For example:
// Syntax -
// type variableName = value;
int age = 25; //Here, age is a variable of int type and we have assigned an integer value 25 to it.
If you want to define a variable whose value cannot be changed, you can use the const
keyword. This will create a constant. For example,
const double PI = 3.14;
PI = 2.9; //Error
Operators and its precedence
An operator is a symbol that operates on a value or a variable. For example: + is an operator to perform addition, in simple Operators are symbols that tell the compiler to perform specific mathematical, relational, or logical operations.
C divides the operators into the following groups:

Examples…
#include <stdio.h>
int main() {
int x = 5;
int y = 5;
//arithmetic operators
printf("y = %d\n", x+y); // Output: 10
printf("%d\n", 5 / 2); // Output: 2 (integer division)
printf("%.1f\n", 5 / 2.0); // Output: 2.5 (float division)
printf("%d\n", 5 % 2); // Output: 1
printf("%d\n", (int)pow(5, 2)); // Output: 25 (requires math.h)
//aasignmnet operators
int a = 5; // '=' is the assignment operator
a += 10; // Equivalent to a = a + 10
printf("a = %d\n", a); // Output: 15
//relational operators
printf("%d\n", 3 < 4); // Output: 1 (true)
printf("%d\n", 3 > 4); // Output: 0 (false)
printf("%d\n", 3 == 4); // Output: 0
printf("%d\n", 3 != 4); // Output: 1
//logical operators
printf("%d\n", (3 > 2) && (2 < 4)); // Output: 1
printf("%d\n", (x < 5) || (x < 4)); // Output: 0
printf("%d\n", !((x < 5) && (x < 10))); // Output: 1
return 0;
}
Bitwise operators work on binary representations of integers (0s and 1s), operating bit-by-bit.

Examples…
#include <stdio.h>
int main() {
int a = 5; // Binary: 0101
int b = 3; // Binary: 0011
// AND
printf("a & b = %d\n", a & b); // 0101 & 0011 = 0001 → Output: 1
// OR
printf("a | b = %d\n", a | b); // 0101 | 0011 = 0111 → Output: 7
// XOR
printf("a ^ b = %d\n", a ^ b); // 0101 ^ 0011 = 0110 → Output: 6
// NOT
printf("~a = %d\n", ~a); // ~0101 = 1010 (in 2's complement: -6)
// Left Shift
printf("a << 1 = %d\n", a << 1); // 0101 becomes 1010 → Output: 10
// Right Shift
printf("a >> 1 = %d\n", a >> 1); // 0101 becomes 0010 → Output: 2
return 0;
}
Expressions
In C, expressions are combinations of variables, constants, operators, and function calls that the compiler evaluates to produce a value.
Expression evaluation may produce a result (e.g., evaluation of 2 + 2 produces the result 4), may generate side-effects (e.g. evaluation of printf(“%d”, 4) sends the character ‘4’ to the standard output stream), and may designate objects or functions.
An expression is anything that returns a value.
Example,
int a = 5 + 3; // '5 + 3' is an expression
Statements — Input and Output statements
A computer program is a list of “instructions” to be “executed” by a computer.
In a programming language, these programming instructions are called statements. The following statement “instructs” the compiler to print the text “Hello World” to the screen: Example — printf(“Hello World!”);
In C programming, input and output (I/O) statements are essential for a program to interact with the user and the external environment. They allow the program to receive data and display results.
C language offers us several built-in functions for performing input/output operations. The following are the functions used for standard input and output:
printf()
function - Show Outputscanf()
function - Take Inputgetchar()
andputchar()
functiongets()
andputs()
function
#include <stdio.h>
int main() {
//using scanf & printf
char user_input[100]; // Use an array to store the name
printf("Please enter your name: ");
scanf("%s", user_input); // %s reads a string (until space)
printf("Hi %s\n", user_input);
return 0;
}
Control Statements
Control statements play a crucial role in C programming, enabling programmers to direct the flow of execution within a program as per their specific requirements.
They provide the means to make decisions, iterate over code blocks, and control the program’s behaviour based on certain predefined conditions.

There are multiple types of control statements in C, including the if-statements and switch statements. These are also known as conditional statements. Other statements are loops (i.e., iterative control statements), break, continue, and goto. The last three are also known as jump control statements.

if Statement
Executes a block of code only if a condition is true.
int age = 18;
if (age >= 18) {
printf("You are eligible to vote.\n");
}
if-else Statement
Chooses between two paths.
int num = 5;
if (num % 2 == 0) {
printf("Even\n");
} else {
printf("Odd\n");
}
else-if Ladder
Checks multiple conditions.
int marks = 75;
if (marks >= 90) {
printf("Grade A\n");
} else if (marks >= 75) {
printf("Grade B\n");
} else {
printf("Grade C\n");
}
switch Statement
Used to select one of many blocks of code to execute.
int day = 3;
switch(day) {
case 1: printf("Monday\n"); break;
case 2: printf("Tuesday\n"); break;
case 3: printf("Wednesday\n"); break;
default: printf("Invalid day\n");
}
Looping (Iterative) Statements
Used for repeated execution.
while Loop
Executes as long as the condition is true.
int i = 1;
while (i <= 5) {
printf("%d\n", i);
i++;
}
do-while Loop
Executes the block at least once, then checks condition.
int i = 1;
do {
printf("%d\n", i);
i++;
} while (i <= 5);
for Loop
Used when number of iterations is known.
for (int i = 1; i <= 5; i++) {
printf("%d\n", i);
}
Jump Statements
These control unexpected flow in loops or blocks.
break Statement
Exits the nearest loop or switch immediately.
for (int i = 1; i <= 5; i++) {
if (i == 3) break;
printf("%d\n", i); // Prints 1, 2
}
continue Statement
Skips the current iteration and continues the loop.
for (int i = 1; i <= 5; i++) {
if (i == 3) continue;
printf("%d\n", i); // Prints 1, 2, 4, 5
}
goto Statement
Jumps to a labeled statement. Use with caution!
int i = 1;
start:
if (i <= 3) {
printf("Hello %d\n", i);
i++;
goto start;
}
Nested Loops in C — With Explanation & Examples
A nested loop means having one loop inside another loop. It is used when you need to perform repetitive actions inside another repetitive action.
Basic Syntax of Nested Loops
for (initialization; condition; update) {
for (initialization; condition; update) {
// Inner loop body
}
// Outer loop body
}
Example: Print a Pattern Using Nested Loops
#include <stdio.h>
int main() {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
printf("* ");
}
printf("\n");
}
return 0;
}
Output

Nested while
Loop
#include <stdio.h>
int main() {
int i = 1;
while (i <= 3) {
int j = 1;
while (j <= 2) {
printf("i = %d, j = %d\n", i, j);
j++;
}
i++;
}
return 0;
}
Note: Inner loop executes completely for every single execution of the outer loop. Avoid infinite loops — always have proper increment and conditions.
Nested loops are commonly used in:
Patterns
Matrices
2D arrays
Games and simulations