I\'ve been messing around with C today and don\'t understand the difference in outputs when I comment out the third buffer in this code:
#include
Try this:
memset(letters, 0x00, 10);
memset(letters, 0x41, 9); /* <--- see the array size minus one there */
that will make the printf(3)
to work properly, but printing a list of nine A
s only. As explained in other responses, this has to do with the nightmare for C programmers to null terminate strings built by hand. For that reason is more common to use the
functions.
In another place, using printf()
's first parameter without a string literal is discouraged, as in the case your string had a %
character, that would be interpreted as a format descriptor, and you would had run into more Undefined behaviour, again.