C Basics — Notes + Enhanced Documentation

This documentation is based on my handwritten notes (C basics) and converted into GitHub Pages friendly Markdown. I have kept the original depth and additionally enhanced each topic with missing important points, debugging tips, and interview-friendly clarifications.


Topics

Tip: Read in order like a short book. Run the examples. Add your own experiments.

C Compilation Process

The full life of a C program. Preprocessing, Compiler, Assembler, Linker.

Memory Layout in C

C program memory segments (text/data/bss/heap/stack), how they grow, and how OS maps memory at runtime.

Pointers in C

Pointer fundamentals, dereferencing, pointer arithmetic, void/NULL pointers, pointer-to-pointer, and common bugs.

Stack Frame & Call Stack

Stack frames, call stack execution flow (LIFO), what gets stored per call, and stack overflow causes.

Arrays & Pointers

Array-pointer relation, `[]` equivalence, array decay, `sizeof` behavior, strings, and pointer-to-array.

Multidimensional Arrays & Pointers

2D/3D array memory model (row-major), correct pointer types, address math, and passing arrays to functions.

Pointers and `const`

All const combinations (`const int*`, `int* const`, `const int* const`) with rule-based understanding and examples.

Function Pointers

Function pointer syntax, callbacks, array of function pointers, and function pointers inside structures.

Dynamic Memory Allocation

`malloc/calloc/realloc/free`, safe realloc pattern, dynamic arrays, and dynamic 2D allocation methods.

Structures in C

Struct usage, dot vs arrow, initialization styles, typedef, passing structs, shallow vs deep copy, self-referential structs.

Padding, Alignment & Packing

Structure padding/alignment, minimizing wasted bytes, and packing using GCC attributes / `#pragma pack`.

C Pointer Practice

This document explains pointer, memory, and data structure concepts using practical C examples.


← Back to C 🏠 Home