Question: Please answer the question and be detailed 3. If the memory allocation works correctly, say so. If it does not, fix it. (a) We want

Please answer the question and be detailed

Please answer the question and be detailed 3. If the memory allocation

3. If the memory allocation works correctly, say so. If it does not, fix it. (a) We want to make a copy of a string. Does the following code work? char msg[] - "message"; char *msg2; msg2 = (char*) malloc (sizeof (char) strcpy(msg2, msg); strlen(msg)); * (b) We want to concatenate two strings into a third string. Does the following code work? char msg1[] - "message "; char msg2[] - "in a bottle"; char *msg3; msg3 - (char *) malloc(strlen (msg1) + strlen(msg2) + 1); strcpy(msg3, msgl); strcat (msg3, msg2); (c) We want to concatenate two arrays into a third array. Does the following code work? int a1[5]0, 1, 2, 3, 4J; int a2[5] - [0, 1, 2, 3, 4}; int *a3, i; a3 - (int *) malloc(10); for (i - 0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!