Author: Megh Badonia
Repository Purpose: Learn the fundamentals of the C programming language with real code examples.
C is a powerful general-purpose programming language developed in the early 1970s. It is fast, efficient, and widely used for system/software development, embedded systems, and operating systems like UNIX.
C is a compiled language, meaning your code must be translated into machine code using a compiler before it can be executed.
#include <stdio.h> // Preprocessor directive
int main() {
printf("Hello, World!\n"); // Output to console
return 0; // Exit status
}| Type | Size (Bytes) | Description |
|---|---|---|
int |
2 or 4 | Integer numbers |
float |
4 | Single-precision float |
double |
8 | Double-precision float |
char |
1 | Single character |
void |
0 | No value (used in functions) |
int age = 25;
float pi = 3.14;
char grade = 'A';Variables must be declared with a type before use.
int number = 10;
const float GRAVITY = 9.81; // Constant valueint a = 5, b = 2;
int sum = a + b; // Add
int diff = a - b; // Subtraction
int prod = a * b; // Multiplication
int div = a / b; // Integer Division
int mod = a % b; // Modulus
a += 1; // Increment
b--; // Decrementint num = 15;
if (num > 0) {
printf("Positive number\n");
} else if (num < 0) {
printf("Negative number\n");
} else {
printf("Zero\n");
}for (int i = 1; i <= 5; i++) {
printf("%d ", i);
}int i = 1;
while (i <= 5) {
printf("%d ", i);
i++;
}int i = 1;
do {
printf("%d ", i);
i++;
} while (i <= 5);int day = 3;
switch (day) {
case 1: printf("Monday"); break;
case 2: printf("Tuesday"); break;
case 3: printf("Wednesday"); break;
default: printf("Invalid day");
}int add(int a, int b) {
return a + b;
}
int main() {
int result = add(3, 4);
printf("Sum: %d", result);
return 0;
}int numbers[5] = {1, 2, 3, 4, 5};
for (int i = 0; i < 5; i++) {
printf("%d ", numbers[i]);
}- Always end statements with a semicolon
; - Use comments to document your code (
// single-line,/* multi-line */) - Indent your code properly for readability
- Compile using
gcc filename.c -o outputand run with./output
Created by Megh Badonia
Feel free to explore, fork, or clone this repository to practice and enhance your C programming skills.
Happy coding! 🚀