Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fill the diagram to show the contents of memory after each line of the following

ID: 3573706 • Letter: F

Question

Fill the diagram to show the contents of memory after each line of the following code: int v1[] = {10, 15}, v2 = 25; int *p1 = v1 + 1, *p2 = &p1; *p1-- = 60; v2 = *p1 + **p_2; Implement char *ExpandedString(char *s, char ch); which creates a new string by inserting the given character ch after each char in the given string s. If there is no memory, it returns NULL. For example, ExpandedString ("ABC", '-'); returns a new string as "A-B-C-" char *ExpandedString(char *s, char ch); {/* Assume standard libraries stdlib.h, stdio.h, string.h are included */

Explanation / Answer

HI, Please find my implementation.

Please let me know in case of any issue.

   Content   
   v1[0]   70
   v1[1]   60
   v2    140
   p1     1004
   p2       1012


   char *ExpandedString(char *s, char ch){

       // finding length of d
       int len = strlen(s);

       // allocating memory for new character array
       char *new_s = (char *)malloc(2*len*sizeof(char));

       if(new_s == NULL){
           printf("Error in creating memory ");
           return NULL;
       }

       int k = 0;
       int i= 0;

       while(i < len){
           new_s[k++] = s[i];
           new_s[k++] = ch;
           i++;
       }

       new_s[k] = '';

       return new_s;
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote