Select a Topic
Choose a subject from the left menu to start learning.
Program for Problem Solving
C is a general-purpose programming language created by Dennis Ritchie at Bell Laboratories in 1972. It is a procedural language that provides low-level access to memory and is widely used for system-level programming.
Every C program starts execution from the main() function. Here is the most basic C program:
// My first C program #include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }
Introduction to Variables
A variable is a named memory location used to store data. In C, every variable must be declared with a data type before it is used.
Syntax: data_type variable_name = value;
#include <stdio.h> int main() { int age = 20; float marks = 95.5; char grade = 'A'; printf("Age: %d\n", age); printf("Marks: %.1f\n", marks); printf("Grade: %c\n", grade); return 0; }
Data Types
Data types define the type and size of data a variable can hold. C has several built-in data types:
int a = 10; // 4 bytes → whole numbers float b = 3.14; // 4 bytes → decimal numbers double c = 9.99; // 8 bytes → large decimals char d = 'A'; // 1 byte → single character void // 0 bytes → no value (functions)
Operators in C
Operators are symbols that perform operations on variables and values. C supports several categories of operators:
// Arithmetic Operators int a = 10, b = 3; printf("%d\n", a + b); // 13 → Addition printf("%d\n", a - b); // 7 → Subtraction printf("%d\n", a * b); // 30 → Multiplication printf("%d\n", a / b); // 3 → Division printf("%d\n", a % b); // 1 → Modulus // Relational Operators printf("%d\n", a == b); // 0 (false) printf("%d\n", a > b); // 1 (true)
Control Structures
Control structures determine the flow of execution in a program. C supports three types: sequential, selection (if/switch), and iteration (loops).
// if-else int marks = 75; if (marks >= 50) { printf("Pass\n"); } else { printf("Fail\n"); } // for loop for (int i = 1; i <= 5; i++) { printf("%d ", i); } // Output: 1 2 3 4 5