AP CSP Procedures Parameters

AP CSP Topics › 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.

2Ways a procedure can behave: with RETURN (returns a value) or without (performs an action)
1Scope rule: variables inside a procedure are local — not visible outside
NArguments matched to parameters left-to-right in the same order

Anatomy of a Procedure

Procedure Call: Parameters and Return Value Caller Code result ← add(3, 5) DISPLAY(result) arguments: 3 and 5 Procedure Definition PROCEDURE add(a, b) sum ← a + b RETURN sum parameters: a=3, b=5 Return Value 8 result stores 8 call return Arguments (3,5) are copied into parameters (a,b). RETURN sends a value back to the caller.

Arguments are copied into parameters. Changes to parameters inside the procedure do NOT affect the caller's variables.

Procedure WITH RETURN
Returns a value to caller
  • 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)
Procedure WITHOUT RETURN
Performs an action, returns nothing
  • 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

Return Value Usage Patterns
PROCEDURE square(n) RETURN n * n result square(4) # result = 16 DISPLAY(square(5)) # displays 25 IF square(3) > 8 # 9 > 8 = TRUE DISPLAY(“big square”)

Code Trace Gauntlet

Trace 1 — Basic Return
PROCEDURE double(x) RETURN x * 2 a double(5) b double(a) DISPLAY(b)

Trace a and b, then predict the output.

Output

20 a = double(5) = 10. b = double(a) = double(10) = 20. Display: 20.

Trace 2 — Procedure Calling Procedure
PROCEDURE add(a, b) RETURN a + b PROCEDURE addThree(x, y, z) RETURN add(add(x,y), z) DISPLAY(addThree(2,3,4))

Trace from inside out. What displays?

Output

9 add(2,3)=5. addThree calls add(5,4)=9. Display: 9.

Trace 3 — Parameters Are Local
PROCEDURE bump(x) x x + 10 RETURN x n 5 result bump(n) DISPLAY(n) DISPLAY(result)

Does changing x inside bump affect n? What are the two outputs?

Output

5 15 n is unchanged (parameters are copies). result = bump(5) = 15. Display: n=5, result=15.

Trace 4 — Conditional Return
PROCEDURE classify(n) IF n > 0 RETURN “positive” ELSE IF n < 0 RETURN “negative” ELSE RETURN “zero” DISPLAY(classify(-7))

What does classify(-7) return and display?

Output

negative n=-7 < 0, so the ELSE IF branch fires and returns “negative”.

Spot the Bug

SPOT THE BUG — Using Return Value of a Void Procedure
PROCEDURE greet(name) DISPLAY(“Hello ” + name) msg greet(“Alice”)
Bug Explained

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.

SPOT THE BUG — Parameter Name Clash Confusion
x 10 PROCEDURE triple(x) RETURN x * 3 DISPLAY(triple(4))
Bug Explained

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

1
Parameters are local copies — changes don’t affect the caller’s variables

Modifying a parameter inside a procedure does not change the variable passed as the argument. The argument is copied into the parameter.

2
A procedure without RETURN cannot be used in an assignment

result ← myProc() only works if myProc has a RETURN statement. Without RETURN, the call is a statement, not an expression.

3
RETURN exits the procedure immediately

Any code after RETURN in the same branch is unreachable. RETURN inside an IF only exits when that branch runs.

4
Argument order must match parameter order

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
a=3, b=7. RETURN 3+7=10. DISPLAY shows 10.

2. PROCEDURE triple(n)
n ← n * 3
RETURN n

x ← 4
y ← triple(x)
DISPLAY(x)

  • 4
  • 12
  • 3
  • Error
x is passed by value. Changing n inside triple does not affect x. x remains 4.

3. Which call correctly uses the return value of a procedure?

  • myProc(5)
  • result ← myProc(5)
  • RETURN myProc(5)
  • myProc ← 5
Storing the return value in a variable: result ← myProc(5). The others either discard the return value or have invalid syntax.

4. PROCEDURE max(a,b)
IF a > b
RETURN a
ELSE
RETURN b

DISPLAY(max(8,5))

  • 5
  • 8
  • a
  • Error
a=8, b=5. 8>5 is TRUE, RETURN a = 8.

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
I and II are correct. III is false — procedures without RETURN are valid (they perform actions but return nothing).

6. PROCEDURE isEven(n)
IF n MOD 2 = 0
RETURN true
ELSE
RETURN false

DISPLAY(isEven(7))

  • true
  • false
  • 0
  • 7
7 MOD 2 = 1, not 0. ELSE fires, RETURN false. Display: false.

7. PROCEDURE calc(a,b)
RETURN a * b + a

DISPLAY(calc(3,4))

  • 15
  • 12
  • 21
  • 7
a=3, b=4. 3*4+3 = 12+3 = 15.

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.
Without RETURN, a procedure produces no value. Assigning its result to total is invalid.

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
Sums all elements: 1+2+3+4=10.

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
Parameters are copies of the arguments. Modifying x inside f does not affect myVar in the caller.

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

What is the difference between a parameter and an argument?
A parameter is the variable name listed in the procedure definition: PROCEDURE add(a, b) has parameters a and b. An argument is the actual value passed when calling: add(3, 5) passes arguments 3 and 5. Arguments are copied into parameters.
Can a procedure call itself?
Yes — this is called recursion. The AP CSP exam does not require writing recursive procedures, but may present one and ask you to trace its output.

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.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]