Without the null on the end of str printf will just continue to print (continuing to read bytes from your stack) until it finds a null value. This is undefined behaviour so what actually happens will depend entirely on the compiler / compiler flags used.
Without optimisation turned on my guess is this will probably appear to work correctly. str[5] will probably reserve 8 bytes of stack (for alignment reasons) and as this is your main function the chances are the extra padding bytes will be 0. Once optimisations are enabled the compiler will move things around so this may not be the case and you may end up printing more than 5 characters. -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/f080e722-2ab6-4cd5-bb5d-a1ab650de136%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
