Accessing or dereferencing a pointer that has not been initialized to a valid memory address.
In C, local variables (including pointers) are not initialized to NULL or 0 by default. They contain whatever garbage data was previously left in stack memory. Dereferencing an uninitialized pointer (a 'wild pointer') causes undefined behavior, modifying random memory or crashing the process.
Declaring a pointer without assigning it a valid address (like NULL or malloc-allocated memory) and then trying to write to or read from its dereferenced target.
1#include <stdio.h>2 3int main() {4 int *ptr; // Wild pointer: points to random garbage memory!5 6 // Undefined Behavior: writing to arbitrary memory address7 *ptr = 100; 8 printf("Value: %d\n", *ptr);9 return 0;10}1#include <stdio.h>2#include <stdlib.h>3 4int main() {5 // Fix: Initialize pointer to NULL and allocate memory6 int *ptr = NULL;7 8 ptr = (int *)malloc(sizeof(int));9 if (ptr == NULL) {10 fprintf(stderr, "Memory allocation failed\n");11 return 1;12 }13 14 *ptr = 100;15 printf("Value: %d\n", *ptr);16 17 free(ptr);18 ptr = NULL; // Prevent dangling pointer19 return 0;20}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
Since ptr is not initialized, it holds a garbage address from the stack. The statement *ptr = 100 attempts to modify the memory at that random address, causing a segmentation fault or memory corruption.