Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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; iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started