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

Info iconThis 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Trace is as follows: (output shown in boxes for clarity only)
Background 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

This document was uploaded on 06/12/2011.

Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online