AQA · GCSE · Computer Science · Higher
Tracing nested subroutine calls
Figure 8 shows a C# program.
| static void First(int p1, int p2, int p3) |
| { |
| int v1 = p2 + p3; |
| Console.WriteLine(Second(v1, p1)); |
| } |
| static int Second(int p1, int p2) |
| { |
| int v1 = p1 + p2; |
| if (v1 > 12) |
| { |
| v1 = v1 + Third(p1); |
| } |
| return v1; |
| } |
| static int Third(int p1) |
| { |
| if (p1 > 3) |
| { |
| return 2; |
| } |
| else |
| { |
| return 0; |
| } |
| } |
State what will be displayed by the Console.WriteLine statement when First is called with the values 3, 4 and 8 for p1, p2 and p3.
Write your answer first. You can study the marking guidance whenever you need it.
Study the marking See what earns credit and compare it with a full-mark answer.
Marking points
- 1 States that 17 is displayed.
Full-mark answer
17
Why this answer loses marks
I traced the outer call but skipped the conditional nested call for this set of arguments.
The condition changes the call path here, so every reached subroutine and returned value must be followed.