AP CSP Procedures Parameters
AP CSP Procedures, Parameters & Return Values: Complete Guide (2025‑2026)
A procedure is a named block of code that performs a specific task. Parameters are the input variables defined in the procedure header; arguments are the actual values passed when calling it. A RETURN statement sends a value back to the caller. Procedures with RETURN can be used in expressions; procedures without RETURN perform an action but give nothing back. This is one of the highest-tested BI1/BI3 topics on the AP CSP exam.
Contents
Anatomy of a Procedure
Arguments are copied into parameters. Changes to parameters inside the procedure do NOT affect the caller's variables.
- Result can be stored: x ← myProc(5)
- Result can be used in expressions
- RETURN exits the procedure immediately
- Useful when caller needs a computed value
- Example: max(a,b), isEven(n), square(x)
- Call is a statement: myProc(5)
- Cannot be used in an assignment
- Runs to end of procedure body
- Useful for output, modifying external state
- Example: printGreeting(name), drawLine()
Return Values
Code Trace Gauntlet
Trace a and b, then predict the output.
20 a = double(5) = 10. b = double(a) = double(10) = 20. Display: 20.
Trace from inside out. What displays?
9 add(2,3)=5. addThree calls add(5,4)=9. Display: 9.
Does changing x inside bump affect n? What are the two outputs?
5 15 n is unchanged (parameters are copies). result = bump(5) = 15. Display: n=5, result=15.
What does classify(-7) return and display?
negative n=-7 < 0, so the ELSE IF branch fires and returns “negative”.
Spot the Bug
greet has no RETURN statement. It displays but returns nothing. Assigning its result to msg is meaningless. Fix: either add RETURN to greet, or remove the assignment and just call greet("Alice") as a statement.
This is NOT a bug — but it is a common misconception. The x inside triple is a LOCAL parameter, separate from the global x=10. triple(4) uses x=4, returns 12. The global x=10 is unaffected. Parameters shadow outer variables.
Common Exam Pitfalls
Modifying a parameter inside a procedure does not change the variable passed as the argument. The argument is copied into the parameter.
result ← myProc() only works if myProc has a RETURN statement. Without RETURN, the call is a statement, not an expression.
Any code after RETURN in the same branch is unreachable. RETURN inside an IF only exits when that branch runs.
PROCEDURE calc(a,b): calling calc(3,5) sets a=3 and b=5. Reversing the call to calc(5,3) swaps the values.
Check for Understanding
1. PROCEDURE add(a,b)
RETURN a + b
DISPLAY(add(3,7))
- 3
- 7
- 10
- a+b
2. PROCEDURE triple(n)
n ← n * 3
RETURN n
x ← 4
y ← triple(x)
DISPLAY(x)
- 4
- 12
- 3
- Error
3. Which call correctly uses the return value of a procedure?
- myProc(5)
- result ← myProc(5)
- RETURN myProc(5)
- myProc ← 5
4. PROCEDURE max(a,b)
IF a > b
RETURN a
ELSE
RETURN b
DISPLAY(max(8,5))
- 5
- 8
- a
- Error
5. Consider: I. A procedure can be called multiple times with different arguments. II. A RETURN statement immediately exits the procedure. III. Every procedure must have at least one RETURN statement.
- I only
- I and II only
- I, II, and III
- II and III only
6. PROCEDURE isEven(n)
IF n MOD 2 = 0
RETURN true
ELSE
RETURN false
DISPLAY(isEven(7))
- true
- false
- 0
- 7
7. PROCEDURE calc(a,b)
RETURN a * b + a
DISPLAY(calc(3,4))
- 15
- 12
- 21
- 7
8. A procedure named printSum has no RETURN statement. The programmer writes: total ← printSum(3,4). What is the problem?
- printSum needs two parameters, not one.
- printSum has no RETURN, so it cannot be used in an assignment expression.
- Variables cannot be assigned from procedure calls.
- The parameters must be named a and b.
9. PROCEDURE addAll(lst)
sum ← 0
FOR EACH x IN lst
sum ← sum + x
RETURN sum
DISPLAY(addAll([1,2,3,4]))
- 4
- 10
- 0
- Error
10. After PROCEDURE f(x): x ← 99 is called with f(myVar), what is myVar?
- 99 — the procedure changed it
- Unchanged — parameters are local copies
- Error — you cannot assign to a parameter
- Depends on whether myVar was declared globally
How the AP Exam Tests This
- Trace a procedure call and determine the return value
- Determine what a caller’s variable equals after a procedure modifies its parameter
- Identify whether a procedure has a return value and whether it can be used in an assignment
- I/II/III: which statements about procedures and parameters are correct
- Find the value returned by a procedure with conditional RETURN branches
FAQ
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]