Code:
char name[5];
char ch = name[5];
char *last_char = &name[5];
ch = *last_char;
...
*last_char = 'A';
name[5] is an area of memory that you shouldn't access. The valid indexes for the name array are 0 through 4. The last character of the array is name[4].
Code:
char *msg = (char *) malloc (5);
You should avoid casting the return value of malloc in C.
Code:
char *msg = (char *) malloc (5);
strcpy (msg, "Hello, ");
strcat (msg, name);
The string "Hello, " requires a buffer of 8 characters (7 + 1 for the terminating null) to store properly. Concatenating "Fred" requires an additional 4 spaces so your buffer must be at least 12 characters but you've only allocated 5.
Code:
msg = (char *) malloc (5);
msg = src;
This is a memory leak, you've allocated space but then repoint the pointer elsewhere immediately after the allocation. You've now lost the pointer to that memory location and have no way to free it.