C Programming Notes: Step-by-Step
1. Introduction to C
- C is a general-purpose, procedural programming language.
- Developed by Dennis Ritchie in 1972.
- Used for system programming, developing operating systems, and embedded systems.
2. Structure of a C Program
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
3. Basic Syntax
- Semicolon (;) marks the end of a statement.
- Braces {} define a block of code.
- Comments: Single-line (//) and multi-line (/* ... */).
4. Data Types
int - Integer (e.g., 5, -3)
float - Floating-point (e.g., 3.14)
char - Character (e.g., 'A')
double - Double-precision float
void - No value
5. Variables and Constants
int x = 10;
const float PI = 3.14;
6. Input and Output
int a;
scanf("%d", &a);
printf("%d", a);
7. Operators
Arithmetic: +, -, *, /, %
Relational: ==, !=, >, <
Logical: &&, ||, !
8. Control Statements
if, else if, else
switch statement
for, while, do-while loops
break, continue
9. Functions
int add(int a, int b) {
return a + b;
}
10. Arrays and Strings
Array: int arr[5];
String: char name[20];
11. Pointers
int a = 10;
int *p = &a;
printf("%d", *p);
12. Structures and Unions
struct Student {
int id;
char name[20];
};
13. File Handling
FILE *fp = fopen("file.txt", "r");
fclose(fp);