C Programming Basics – Beginner Notes
1. What is C? - C is a general-purpose, procedural programming language. - Developed by Dennis
Ritchie in 1972 at Bell Labs. - It is fast, efficient, and widely used for system programming,
embedded systems, etc.
2. Structure of a Simple C Program: #include int main() { printf("Hello, World!\n"); return 0; } -
#include includes standard input-output functions. - int main() is the main function where execution
starts. - printf() prints output. - return 0; returns success code to OS.
3. Data Types in C: - int (4 bytes): int age = 20; - char (1 byte): char letter = 'A'; - float (4 bytes): float
price = 5.99; - double (8 bytes): double pi = 3.14159; - void: Used for functions with no return.
4. Variables and Constants: - Variable Declaration: int age; float price; char letter; - Assigning
Values: age = 25; price = 99.99; letter = 'C'; - Constants: const int DAYS_IN_WEEK = 7;
5. Operators: - Arithmetic: + - * / % - Comparison: == != > < >= <= - Logical: && || ! - Assignment: =
+= -= *= /= %=
6. Control Structures: - If-Else: if (age > 18) { printf("Adult\n"); } else { printf("Minor\n"); } - Switch
Case: switch(option) { case 1: printf("Option 1\n"); break; default: printf("Invalid option\n"); } - Loops:
For loop: for(int i=0;i<5;i++){ printf("%d\n", i); } While loop: while(i<5){ printf("%d\n", i); i++; }
Do-While loop: do { printf("%d\n", i); i++; } while(i<5);
7. Functions in C: Example: #include int add(int a, int b); int main() { int result = add(5,3);
printf("Result: %d\n", result); return 0; } int add(int a, int b) { return a + b; }
8. Arrays: int numbers[5] = {1,2,3,4,5}; printf("%d\n", numbers[0]); // Output: 1
9. Pointers: int a = 10; int *p = &a; printf("%d\n", *p); // Output: 10
10. Input/Output Functions: printf("Enter your age: "); scanf("%d", &age;); printf("You are %d years
old.\n", age);
Tips for Beginners: - Always include #include . - End each statement with a semicolon. - Practice
small programs. - Understand variables, functions, arrays. - Debug carefully.