Help with tracing problems

# Help with tracing problems - Help with tracing problems To...

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

Help with tracing problems. To trace through code that uses functions use a trace table and follow the changes to the variables. What is the output of the following program segment? int A = 2 , B = 3; A B cout << A << " " << B << " "<< two(A, B) << endl; 2 3 output: int two(int s, int t) Trace table: ( s and t get the values passed to them from the caller) { s t b int b; 2 3 ? b = s + t; 5 s *= b + 2; 14 b += 2 * s ; 32 return ( b ) ; 32 is returned to the calling program } Considering the following function: Trace table int one(int x, int y) { x y a int a; 3 5 ? a = x * y; 15 x += y / 2 ; 5 a += y + x; 25 return a ; 25 is returned to the calling program } Trace table: What is the output of the following program segment? u v a int u = 5, v = 3, a = 4; 5 3 4 a += one( v, u); 29 cout << u << " " << v << "\n" << a <<endl ; prints: 5 3 29 When dealing with mathematical operations you need to remember 3 things: 1) Order of operation ( *, /, % first and then + and – with () taking priority) 2) Data types ( mixed data types always result in the higher type for example any int operated with float

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 2

Help with tracing problems - Help with tracing problems To...

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

View Full Document
Ask a homework question - tutors are online