{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

tracing - a = 3 b = 3 c = 6 c = operation(3,3 The values...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 3502 –Another Tracing Example Tracing Code with Functions Here is another example that you can try. void magic ( ) { int a = 3; int b = 3; int c; c = operation(a, b); printf(“The values are %d, %d, %d \n”, a, b, c); mystify(&a, &b, c); printf(“The values are %d, %d, %d \n”, a, b, c); mystify(&c, &b, a); printf(“The values are %d, %d, %d \n”, a, b, c); printf(“Execution ends.\n”); } int operation(int num1, int num2) { if (num1 > num2) return num1 * num2; else return num1 + num2; } void mystify (int *num1, int *num2, int num3) { num3 = num3 – 1; *num1 = *num1 + num3; *num2 = *num1 + *num2; printf(“In mystify the values are %d, %d, %d \n”, *num1, *num2, num3); } 1
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Trace is as follows: (output shown in boxes for clarity only)
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a = 3 b = 3 c = 6 c = operation(3,3) The values are: 3 3 6 Mystify(3, 3, 6) (Mystify(a, b, c)) parameters are: num1 = 3, num2 = 3, num3 = 6 num3 = 5 (6-1) num1 = 8 (3+3) num2 = 11 (8+3) In Mystify the numbers are: 8 11 5 return values are: num1 = 8, num2 = 11 a = 8, b = 11, c = 6 The values are: 8 11 6 Mystify(6, 11, 8) (Mystify(c, b, a)) parameters are: num1 = 6, num2 = 11, num3 = ← 8 num3 = 7 (8-1) num1 = 13 (6+7) num2 = 24 (13+11) In Mystify the numbers are: 13 24 7 return values are: num1 = 13, num2 = 24 a ← 8, b ← 24, c ← 13 The values are: 8 24 13 Execution ends 2...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern