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 4 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 11 is displayed.
Full-mark answer
11
Why this answer loses marks
I used the intermediate value from the first subroutine calculation as the displayed result.
This call continues through nested calls and returns before the output statement displays the final value.