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;
}
Complete Beginner to Pro Guide
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
int age = 25;
float salary = 45000.50f;
double pi = 3.14159265359;
char grade = 'A';
int isPass = 1; // 1 = true, 0 = false
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
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)
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");
}
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);
int numbers[5] = {10, 20, 30, 40, 50};
printf("%d\n", numbers[1]); // 20
printf("%zu\n", sizeof(numbers)/sizeof(numbers[0])); // 5
#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;
}
int age = 22;
int *ptr = &age;
printf("Value: %d\n", *ptr); // 22
printf("Address: %p\n", (void*)ptr);
*ptr = 25; // age becomes 25
\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");
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);
#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;
}