Advanced C Programming - Topic-wise Notes
UNIT-I: Arrays
- Arrays are collections of elements of the same data type stored in contiguous memory locations.
- One-dimensional arrays: int arr[10];
- Two-dimensional arrays: int matrix[3][3];
- Accessing elements: arr[0], matrix[1][2];
- Array initialization: int arr[] = {1, 2, 3};
- Sorting: Bubble sort, Selection sort etc.
- Arrays and functions: Passing arrays to functions using pointers.
- Memory representation: Row-major (C style) and column-major.
UNIT-II: Pointers
- Pointer: A variable that stores the address of another variable.
- Declaration: int *p;
- Initialization: int a = 10; p = &a;
- Indirection operator (*), Address-of operator (&)
- Pointer arithmetic: p++, p--, p+n
- Dynamic memory allocation: malloc(), calloc(), free()
- Pointers and arrays: int *p = arr;
UNIT-III: Strings
- Strings are arrays of characters ending with null character '\0'.
- Declaration: char str[20] = "Hello";
- Initialization: char str[] = {'H','e','l','l','o','\0'};
- Functions: strlen(), strcpy(), strcat(), strcmp()
- Manual implementation using loops.
UNIT-IV: Structures and Unions
Advanced C Programming - Topic-wise Notes
- Structures: Group of variables of different types.
- Declaration: struct student {int id; char name[20];};
- Access fields using dot operator: s1.id
- Nested structures: struct dept {struct student s; int code;};
- Union: Similar to structure but shares memory.
- Difference: Structure allocates memory for all members, Union for largest one.
UNIT-V: Preprocessor and Bitwise Operators
- Preprocessor: Handles directives before compilation.
- Macro: #define PI 3.14
- File inclusion: #include <stdio.h>
- Conditional compilation: #ifdef, #ifndef, #endif
- Bitwise operators: &, |, ^, ~, <<, >>
- Bit fields and masks: Used to access specific bits.
UNIT-VI: File Handling
- File: Collection of data stored on disk.
- Opening: FILE *fp = fopen("data.txt", "r");
- Closing: fclose(fp);
- Functions: fgetc(), fputc(), fprintf(), fscanf()
- Random access: fseek(), ftell(), rewind()
- Command line arguments: main(int argc, char *argv[])