just say "Visca Barça" and star coding
Master
C Programming with
Pavel Ibrahim
Every topic from basics to advanced — with fully commented code examples, flowcharts, tables, and a 20-question quiz. Your ultimate C reference.
Introduction to Programming
Programming is the art of giving step-by-step instructions to a computer to solve problems.
A program is a set of instructions written in a language the computer understands. Computers only understand binary (0s and 1s), so languages bridge the gap. C is called a middle-level language.
/* ============================================= Program : Hello, World! Purpose : Print text to screen — simplest C program How : printf() outputs to stdout ============================================= */ #include <stdio.h> /* Standard I/O header — gives us printf(), scanf() Without this, printf won't be recognized */ /* main() — the ENTRY POINT of every C program Execution always starts here, not anywhere else 'int' means it returns an integer to the OS */ int main() { /* printf() — print formatted text to console \n = newline character (moves cursor to next line) */ printf("Hello, World!\n"); /* return 0 — signals OS that program ran successfully Non-zero return values indicate errors */ return 0; }
gcc program.c -o output| Level | Language | Example |
|---|---|---|
| Machine | Binary | 01001010 |
| Low | Assembly | MOV AX, 5 |
| Middle | C, C++ | int x = 5; |
| High | Python | x = 5 |
/* ============================================= Program : Basic Arithmetic Operations Purpose : Demonstrate all 5 arithmetic operators in C Input : None (uses hardcoded values) Output : Results of addition, subtraction, multiplication, division, modulus ============================================= */ #include <stdio.h> /* Include standard input/output library Provides printf() function for output */ int main() { /* main() function - program entry point int return type indicates program status to OS */ /* Variable declarations with initialization int data type stores whole numbers (no decimals) Multiple variables can be declared in one line */ int a = 10, b = 5; /* ARITHMETIC OPERATORS IN C: + (addition), - (subtraction), * (multiplication) / (division), % (modulus/remainder) */ /* Addition operator: adds two numbers */ printf("Addition: %d + %d = %d\n", a, b, a + b); /* Subtraction operator: subtracts second number from first */ printf("Subtraction: %d - %d = %d\n", a, b, a - b); /* Multiplication operator: multiplies two numbers */ printf("Multiplication: %d * %d = %d\n", a, b, a * b); /* Division operator: divides first number by second Integer division truncates decimal part (no rounding) */ printf("Division: %d / %d = %d\n", a, b, a / b); /* Modulus operator: gives remainder after division Useful for checking even/odd, cycling through ranges */ printf("Modulus: %d %% %d = %d\n", a, b, a % b); /* Return 0 indicates successful program execution */ int main() { /* main() function - program entry point int return type indicates program status to OS */ /* Variable declarations with initialization int data type stores whole numbers (no decimals) Multiple variables can be declared in one line */ int a = 10, b = 5; /* ARITHMETIC OPERATORS IN C: + (addition), - (subtraction), * (multiplication) / (division), % (modulus/remainder) */ /* Addition operator: adds two numbers */ printf("Addition: %d + %d = %d\n", a, b, a + b); /* Subtraction operator: subtracts second number from first */ printf("Subtraction: %d - %d = %d\n", a, b, a - b); /* Multiplication operator: multiplies two numbers */ printf("Multiplication: %d * %d = %d\n", a, b, a * b); /* Division operator: divides first number by second Integer division truncates decimal part (no rounding) */ printf("Division: %d / %d = %d\n", a, b, a / b); /* Modulus operator: gives remainder after division Useful for checking even/odd, cycling through ranges */ printf("Modulus: %d %% %d = %d\n", a, b, a % b); /* Return 0 indicates successful program execution */ return 0; }
Subtraction: 10 - 5 = 5
Multiplication: 10 * 5 = 50
Division: 10 / 5 = 2
Modulus: 10 % 5 = 0
/* ============================================= Program : Input and Output Demonstration Purpose : Show how to read user input and display formatted output Input : User's name (string), age (integer), height (float) Output : Personalized greeting with user data ============================================= */ #include <stdio.h> /* Include standard I/O library Provides printf() for output and scanf() for input */ int main() { /* Program entry point */ /* VARIABLE DECLARATIONS: Different data types for different kinds of data Variables declared but not initialized (will be set by user input) */ int age; /* Integer variable for whole numbers (age in years) */ char name[50]; /* Character array for strings (up to 49 chars + null terminator) */ float height; /* Float variable for decimal numbers (height in meters) */ /* INPUT OPERATIONS USING scanf(): scanf() reads formatted input from keyboard (stdin) Format specifiers tell scanf what type of data to expect */ /* Prompt user and read string input %s format reads until whitespace (space, tab, newline) */ printf("Enter your name: "); scanf("%s", name); /* Note: NO & needed for arrays (name is already an address) */ /* Prompt user and read integer input %d format reads whole numbers, &age gives address of age variable */ printf("Enter your age: "); scanf("%d", &age); /* & (address-of operator) required for non-array variables */ /* Prompt user and read float input %f format reads decimal numbers */ printf("Enter your height in meters: "); scanf("%f", &height); /* OUTPUT OPERATIONS USING printf(): printf() displays formatted text to screen (stdout) Format specifiers (%s, %d, %f) are replaced with variable values */ printf("\nHello %s!\n", name); /* %s for strings */ printf("You are %d years old.\n", age); /* %d for integers */ printf("Your height is %.2f meters.\n", height); /* %.2f for float with 2 decimal places */ /* Program completed successfully */ return 0; }
25
1.75
Sample Output: Hello John!
You are 25 years old.
Your height is 1.75 meters.