// The correct way of building the string "Monday" character by character. // The problem is that, instead of putting the NULL character at the end, // we put the '0' character. #include // necessary for printf #include // necessary for malloc int main() { char * m = (char *) malloc(sizeof(char) * 7); m[0] = 'M'; m[1] = 'o'; m[2] = 'n'; m[3] = 'd'; m[4] = 'a'; m[5] = 'y'; m[6] = 0; // the correct way, putting the NULL character at the end of the string. // What will be printed here is unpredictable, because // printf has no way of knowing how long string m is. // We will definitely see Monday0 printed, possibly // followed by junk. printf("string m is %s\n\n", m); }