AP CSP Day 38: Procedures & Parameters | Cycle 2

Key Concepts

Procedure call errors include passing arguments in the wrong order, passing the wrong number of arguments, or misunderstanding which variable receives a return value. When a procedure has two parameters of the same type, swapping the argument order produces logically incorrect but syntactically valid code that is difficult to detect. AP CSP Cycle 2 procedure questions present a procedure definition alongside a set of calls, and ask students to identify which call produces an incorrect result due to argument order or scope misunderstanding.

📚 Study the Concept First (Optional) Click to expand ▼

Procedure Call Bugs: Wrong Arguments

Argument Order Error

When a procedure accepts multiple parameters, passing arguments in the wrong order produces incorrect results without any syntax error. If divide(a, b) computes a / b, then calling divide(10, 2) returns 5 but calling divide(2, 10) returns 0.2.

Wrong Number of Arguments

Passing too few or too many arguments to a procedure is an error. Each parameter must receive exactly one argument.

Common Trap: Assuming argument order does not matter because the variable names are similar. Always match arguments to parameters by position, not by name similarity.
Exam Tip: When reading a procedure call, look at the procedure definition first to identify what each parameter represents. Then verify each argument is in the correct position for the intended computation.
Big Idea 3: Algorithms & Programming
Cycle 2 • Day 38 Practice • Hard Difficulty
Focus: Procedures & Parameters

Practice Question

What is displayed after the following code runs?

PROCEDURE calculate(x, y)
{
   result ← x * y + x
   RETURN result
}

a ← 3
b ← calculate(a, a + 1)
DISPLAY(b)
Why This Answer?

The argument a + 1 is evaluated before the call: a + 1 = 3 + 1 = 4. So calculate(3, 4) executes. Inside: result = 3 * 4 + 3 = 12 + 3 = 15. The returned value 15 is stored in b and displayed.

Why Not the Others?

A) 12 results from computing x * y (3*4) but forgetting to add x. C) 9 results from x * x = 3*3, ignoring the second parameter. B) 16 results from (x+1) * y = 4*4, substituting incorrectly.

Common Mistake
Watch Out!

Students either forget to evaluate the argument expression (a+1) before passing it, or they compute x*y and stop without adding the final x term.

AP Exam Tip

Always evaluate argument expressions completely before substituting into the procedure. Then trace the procedure body with the substituted values, following order of operations.

Keep Practicing!

Consistent daily practice is the key to AP CSP success.

AP CSP Resources Get 1-on-1 Help
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.