Dynamic Memory Allocation + Pointers
Pointers Pointer — stores the address of a variable int *a = &b → a is a pointer to the address of b → use *a to access b int &a = b → a is alias (reference) to b → both share the same address → use a to access b arr [ 3 ] = { 5 , 10 , 20 }; // *arr → 5 // *(arr + 1) → 10 // For 2-D array: *(*arr + 1) → arr[0][1] *(*(arr + 1)) → arr[1][0] Dereferencing Retrieve the data stored at the memory location a pointer points to. Void pointers give great flexibility — they can point to any data type. But to dereference → first cast it to a concrete data type. Memory Leak When a program forgets to deallocate memory, making it unavailable for future use. m = malloc ( 5 ); m = NULL ; // Allocates 5 bytes on heap → stores address in pointer m // Sets m = NULL → program loses that address // No pointer refers to that memory anymore // → Cannot be accessed or freed for the lifetime of the program Dangling Pointer d...