One of the fundamental things you need to know as a software engineer is how the stack and heap work. Today we will address one of the most common questions which is what happens when the stack and the heap collide.

When the stack and heap collide, it means that both memory regions start overlapping with each other.

When main() tries to use the pointer variable after calling func(), it can result in unexpected behavior if the stack and heap overlap.

func() re-assigns the passed pointer variable to another pointer on the stack and frees the heap memory.

Related Articles