DEV Community

Discussion on: I'm an Expert in Memory Management & Segfaults, Ask Me Anything!

Collapse
 
natepolizogo profile image
NatePolizogo

I think I kinda located the problem but i cant understand why is this happening. As you can see at the image above i for some reason decides to be whatever value it want's despite the fact that it is in a for loop.

Thread Thread
 
natepolizogo profile image
NatePolizogo
Thread Thread
 
codemouse92 profile image
Jason C. McDonald

for some reason decides to be whatever value it want's despite the fact that it is in a for loop.

This means it is reading from uninitialized memory. Common reasons for this:

  • You declared a variable, or dynamically allocated memory, but never initialized the memory with a value.

  • You are using a pointer (or reference) to either a position in memory which has already been freed (dangling pointer/reference), or which has never been allocated (wild pointer/reference). This can happen with either the heap or the stack; it's not limited to dynamic allocation.

  • You are exceeding the boundaries of an array or string (buffer overrun).