I\'m new to C. Sorry if this has already been answered, I could\'n find a straight answer, so here we go..
I\'m trying to understand how malloc() works in C. I have this
Simply this is one of the case of undefined behavior. You are unlucky that you are getting the expected result.