1) What is the output of the program? (2) Does this program have any memory leak? If yes, where should free be placed? u

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

1) What is the output of the program? (2) Does this program have any memory leak? If yes, where should free be placed? u

Post by answerhappygod »

1) What is the output of the program?
(2) Does this program have any memory leak? If yes, where
should free be placed? use line number in the figure to
answer. A sample answer could be "free should be placed under
line 23".
(3) What is unknown function 1? choosing
from main, mystery and verify_array.
(4) What is unknown function 2? choosing
from main, mystery and verify_array.
(5) What is the variable name of unknown_var 3?
(6) What is the value of unknown_var 2?
1 What Is The Output Of The Program 2 Does This Program Have Any Memory Leak If Yes Where Should Free Be Placed U 1
1 What Is The Output Of The Program 2 Does This Program Have Any Memory Leak If Yes Where Should Free Be Placed U 1 (175.59 KiB) Viewed 43 times
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 int verify_array(char * s) { 5 for(int i=0; i<strlen(s); i++) 6 if(!(s=='.' || s == 'C' || s==')' || 7 (s <='9' && s >= '0'))) { return 0; 9 } 10 return 1; 8 11 } 12 13 v char * mystery(char * arr, int size) { 14 char * new_num = (char*) malloc(sizeof(char)*(size+6)); 15 char code [5] = "(212)"; 16 for (int i =0;i<5;i++) 17 { 18 new_num=code; 19 } 20 for (int i=0;i<=size;i++) { 22 new_num [5+i)=arr; 23 } 24 25 size = size +5; 26 return new_num; 21 27 } 28 29 int main(void) { 30 char number[] = "745-1234"; 31 char * ret; 32 int size = strlen(number); 33 ret = mystery (number, size); 34 if(verify_array(ret)) 35 printf("mystery return: %s, %d", ret, size); 36 return 0; 37 }

Starting address: Oxdeadbeef (212) 745 Low address - 1 2 3 4 Heap unknown function 1 unknown_var 1: unknown function 2 unknown_var 2: unknown_var 3: Oxdeadbeaf undefined unknown_var 4: 74/5 - 1 2 3 4 High address Stack
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply