C Programming Notes
1. Introduction
C is a general-purpose, structured, and procedural programming language. It was developed by
Dennis Ritchie in 1972 at Bell Labs. C is widely used for system programming, operating systems,
and embedded systems.
2. Structure of a C Program
#include
int main() {
printf("Hello World");
return 0;
}
3. Data Types
Basic: int, float, double, char
Derived: array, pointer, structure, union
Void: no value
4. Variables & Constants
Variable: Named storage location (e.g., int age = 20;)
Constant: Fixed value (e.g., const float PI = 3.14;)
5. Operators
Arithmetic: + - * / %
Relational: == != > < >= <=
Logical: && || !
Assignment: = += -= *= /=
Increment/Decrement: ++ --
6. Control Statements
Decision Making: if, if-else, switch
Loops: for, while, do-while
7. Functions
int add(int a, int b) { return a + b; }
Types: Library Functions (printf, scanf, sqrt), User Defined Functions
8. Arrays
Collection of similar data
Example: int marks[5] = {90, 80, 70, 60, 50};
9. Strings
Array of characters
Example: char name[] = "Hello";
10. Pointers
Pointer is a variable that stores memory address.
Example: int a = 10; int *p = &a;
11. Structures
Example:
struct Student {
int roll;
char name[20];
float marks;
};
12. File Handling
FILE *fp;
fp = fopen("data.txt", "w");
fprintf(fp, "Hello File");
fclose(fp);