// An incorrect way of building the string "Monday" character by character. // The problem is that we do not put the NULL character at the end. // See Monday2.cpp for the correct version. #include // necessary for printf #include // necessary for malloc int main() { char * m = (char *) malloc(sizeof(char) * 6); m[0] = 'M'; m[1] = 'o'; m[2] = 'n'; m[3] = 'd'; m[4] = 'a'; m[5] = 'y'; // what will be printed here is unpredictable, because // printf has no way of knowing how long string m is. printf("string m is %s\n\n", m); }