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

draw the snap shot of the stack (picture of how the stack will look like) when 3

ID: 669694 • Letter: D

Question

draw the snap shot of the stack (picture of how the stack will look like) when 3rd line of the func2() code is reached. The picture should be similar to what is shown in the bold font on slide #45".

Stack:

void func2(char * str2) {

   char buf2[16];

   strcpy(buf2,str2); /* line #3 in func2() */

}

void func1(char * str1) {

   char buf1[256];

   strcpy(buf1,str1);

   func2(buf1);   

}

void main() {

    char large_str[256];

    int i;

    for( i = 0; i < 255; i++)

      large_str[i] = 'A';

    func1(large_str);

    printf(“str copied! ”);

}

Stack Overflow Example Code memory (L) Stack top void function (char *str) t esp-> buf[15] char buf [16] strcpy (buf.str): push ebp buf [0] esp-19esp 0 void main) char large str [256]; int i for. A = 0;

Explanation / Answer

large_str:
A|A|A
buf1:
A|A|A
buf2:
A|A|A