⬅ Menu

C Notes 2026

Complete Beginner to Pro Guide

1. Hello World Program

The classic first program — prints a message to confirm your C environment is working.
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

2. Data Types

Basic building blocks that determine the type and size of data a variable can store.
int age = 25;
float salary = 45000.50f;
double pi = 3.14159265359;
char grade = 'A';
int isPass = 1;     // 1 = true, 0 = false

3. Variables & Constants

Named memory locations to store data — use const for values that shouldn't change.
int marks = 85;
marks = 92;           // OK

const float PI = 3.14159f;
// PI = 3.0;          // Error - cannot modify const

4. Operators

Perform arithmetic, comparison, logical, and bitwise operations.
int a = 10, b = 3;
printf("%d\n", a + b);     // 13
printf("%d\n", a > b);     // 1 (true)
printf("%d\n", a % b);     // 1
printf("%d\n", a & b);     // 2 (bitwise AND)

5. If-else & Switch

Control flow statements for decision making.
int marks = 78;

if (marks >= 90) {
    printf("A+\n");
} else if (marks >= 60) {
    printf("Pass\n");
} else {
    printf("Fail\n");
}

// Switch
int day = 3;
switch (day) {
    case 1: printf("Monday\n"); break;
    case 2: printf("Tuesday\n"); break;
    default: printf("Other day\n");
}

6. Loops

Repeat a block of code — for, while, do-while are the three main types.
for (int i = 1; i <= 5; i++) {
    printf("%d ", i);
}

int count = 1;
while (count <= 5) {
    printf("%d ", count);
    count++;
}

do {
    printf("Executed at least once\n");
} while (0);

7. Arrays

Collection of elements of the same type stored in contiguous memory.
int numbers[5] = {10, 20, 30, 40, 50};
printf("%d\n", numbers[1]);     // 20
printf("%zu\n", sizeof(numbers)/sizeof(numbers[0])); // 5

8. Functions

Reusable blocks of code that perform a specific task.
#include <stdio.h>

int add(int x, int y) {
    return x + y;
}

int main() {
    int result = add(5, 7);
    printf("Sum = %d\n", result);   // 12
    return 0;
}

9. Pointers

Variables that store memory addresses — one of the most powerful (and tricky) features in C.
int age = 22;
int *ptr = &age;

printf("Value: %d\n", *ptr);      // 22
printf("Address: %p\n", (void*)ptr);
*ptr = 25;                        // age becomes 25

10. Strings

In C, strings are arrays of characters ending with null terminator \0.
#include <string.h>

char name[] = "Md";
printf("%s\n", name);              // Md
printf("%zu\n", strlen(name));     // 2

char greeting[20];
strcpy(greeting, "Hello 2026");

11. Structures

User-defined data type that groups different data types together.
struct Student {
    char name[50];
    int age;
    float gpa;
};

struct Student s1;
strcpy(s1.name, "Md");
s1.age = 22;
s1.gpa = 3.8;

printf("%s is %d years old\n", s1.name, s1.age);

12. File Handling

Read from and write to files using standard I/O functions.
#include <stdio.h>

int main() {
    FILE *fp = fopen("data.txt", "w");
    if (fp != NULL) {
        fprintf(fp, "Hello from C 2026!\n");
        fclose(fp);
    }
    return 0;
}