C Programming Language Notes
1. Introduction to C:
- Developed by Dennis Ritchie in 1972.
- General-purpose, procedural programming language.
- Used for system programming, OS development, embedded systems.
2. Structure of a C Program:
#include <stdio.h>
int main() {
// code
return 0;
}
- Every C program starts with main().
- #include is used to include standard libraries.
3. Basic Data Types:
- int: Integer type.
- float: Floating point number.
- double: Double precision float.
- char: Character type.
- Modifiers: short, long, signed, unsigned.
4. Variables and Constants:
- Variables are named locations in memory to store data.
- Constants are values that do not change during execution.
- Syntax for declaring constants: const int x = 10;
5. Operators:
- Arithmetic: +, -, *, /, %
- Relational: ==, !=, >, <, >=, <=
- Logical: &&, ||, !
- Assignment: =, +=, -=, *=, /=
6. Control Statements:
- Decision making: if, if-else, switch
- Loops: for, while, do-while
- Jump statements: break, continue, goto
7. Functions:
- Functions help in modular programming.
- Syntax: return_type function_name(parameters) { //code }
- Functions can be called from main or other functions.
- Example:
int add(int a, int b) {
return a + b;
}
8. Arrays and Strings:
- Arrays: Collection of elements of same type, accessed by index.
Example: int arr[5] = {1, 2, 3, 4, 5};
- Strings: Character arrays ending with ''.
Example: char str[] = "Hello";
9. Pointers:
- A pointer stores the address of a variable.
- Declared with * operator. Example: int *ptr;
- & gives address of variable, * dereferences pointer.
10. Structures and Unions:
- Structure: Custom data type with multiple variables.
Example:
struct Student {
int id;
char name[50];
};
- Union: Similar to structure, but shares memory space.
11. File Handling:
- Reading and writing files using standard functions.
- fopen(), fclose() - open/close file
- fprintf(), fscanf() - formatted input/output
- fgetc(), fputc() - character input/output
12. Important Header Files:
- stdio.h: Standard I/O functions
- stdlib.h: General utilities like malloc, free
- string.h: String handling functions
- math.h: Math functions like sqrt, pow
- conio.h: Console I/O (non-standard)
Tips:
- Practice by writing programs daily.
- Focus on logic building and understanding memory management.
- Debug and test your code thoroughly.