When transitioning from memory-managed languages like JavaScript to systems languages like C, the mental model of where variables live becomes critical. One of the most common architecture traps beginners and intermediate developers face is managing memory across function boundaries.

Specifically: attempting to manipulate or return pointers to local structures allocated on the stack.

This guide breaks down the physical mechanics of the stack, why direct pointer manipulation on local structs frequently causes segmentation faults, and how to safely handle stack data without crashing your application.

The Problem: Stack Frame Lifecycles

When you declare a struct inside a function locally (e.g., contact add_psn;), the compiler allocates that memory space within the current function's stack frame.