// An incorrect 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. // See Monday2.cpp for the correct version. #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'; // this is the wrong line, compare with Monday2.cpp // 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); }