I am wondering how does printf() figure out when to stop printing a string, even I haven\'t put a termination character at the end of the string? I did an experiment by mall
Assuming you really did malloc 10 characters, and you really did set each and every character with a value other than null ('\0'), then where is the guarantee that the character you didn't allocate which immediately followed in memory wasn't null by chance?
You may have used one of a number of function calls that are smart enough to set the last character as null, even if you passed it enough information to possibly "set" is to be non-null, but with so few details, we will never know.