Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago