Advanced C Programming – In■Depth Notes
Covers advanced concepts with explanations for interviews, exams, and real■world programming.
1. Memory Architecture of C
• Stack Memory: Used for local variables and function calls. Automatically managed.
• Heap Memory: Used for dynamic allocation. Managed manually using malloc/free.
• Data Segment: Stores global and static variables.
• Code Segment: Stores compiled program instructions.
2. Pointers – Deep Dive
• Pointer to pointer and multi■level indirection.
• Pointer arithmetic and scaling.
• Null, dangling, and wild pointers.
• Pointers with arrays and strings.
• Function pointers and callbacks.
3. Dynamic Memory Management
• malloc(): Allocates uninitialized memory.
• calloc(): Allocates and initializes memory to zero.
• realloc(): Resizes previously allocated memory.
• free(): Releases allocated memory.
• Memory leaks and how to avoid them.
4. Storage Classes
• auto: Default storage for local variables.
• register: Suggests storage in CPU register.
• static: Preserves value between function calls.
• extern: Used to reference global variables across files.
5. Preprocessor Directives
• #define macros and constants.
• Parameterized macros.
• Conditional compilation (#if, #ifdef).
• Header guards and best practices.
6. Structures and Advanced Usage
• Nested structures.
• Structures with pointers.
• Array of structures.
• Structure padding and alignment.
• typedef with structures.
7. Unions vs Structures
• Memory sharing concept.
• Use cases of unions.
• Difference between union and structure.
8. File Handling – Advanced
• Text vs binary files.
• File positioning (fseek, ftell, rewind).
• Error handling in files.
• Reading/writing structures to files.
9. Command Line Arguments
• argc and argv usage.
• Passing arguments from command line.
• Practical examples.
10. Bitwise Operations
• Bitwise AND, OR, XOR.
• Left shift and right shift.
• Bit masking techniques.
• Use in embedded systems.
11. Multidimensional Arrays & Pointers
• Pointer representation of 2D arrays.
• Dynamic 2D arrays.
• Memory layout understanding.
12. Error Handling
• Using errno.
• perror() and strerror().
• Common runtime errors.
13. Optimization & Best Practices
• Reducing memory usage.
• Avoiding undefined behavior.
• Efficient looping techniques.
• Code readability and maintainability.
14. Interview■Important Concepts
• Difference between malloc and calloc.
• Array vs pointer.
• Structure vs union.
• Stack vs heap.
• Common tricky questions.