C LANGUAGE NOTES
1. Introduction to C
- Developed by: Dennis Ritchie (1972)
- Features: Procedural, Structured, Low-level memory access, Fast
- Uses: System software, Embedded systems, Compilers
2. Structure of a C Program
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
3. Basic Syntax
- Semicolon (;): Ends a statement
- Comments:
// Single-line
/* Multi-line */
4. Data Types
- int: 2 or 4 bytes (e.g., 10)
- float: 4 bytes (e.g., 3.14)
- char: 1 byte (e.g., 'A')
- double: 8 bytes (e.g., 3.14159)
5. Variables & Constants
int a = 10;
const float pi = 3.14;
6. Operators
- Arithmetic: + - * / %
- Relational: == != > < >= <=
- Logical: && || !
- Assignment: = += -= *=
7. Input & Output
scanf("%d", &a); // Input
printf("%d", a); // Output
8. Control Statements
- if, else if, else
- switch case
- Loops: for, while, do...while
Example:
for (int i = 0; i < 5; i++) {
printf("%d", i);
9. Functions
int add(int a, int b) {
return a + b;
}
10. Arrays
int arr[5] = {1, 2, 3, 4, 5};
11. Strings
char name[] = "Rohan";
12. Pointers
int a = 10;
int *ptr = &a;
13. Structures
struct Person {
char name[20];
int age;
};
14. File Handling
FILE *fp;
fp = fopen("data.txt", "r");
fclose(fp);