AP CSP Day 8: Procedures And Parameters

Key Concepts

A procedure (also called a function or subroutine) is a named block of code that can be called multiple times with different inputs called parameters. Parameters are local to the procedure and receive their values from the arguments passed during the call. AP CSP exam questions often test whether students understand that calling a procedure with specific arguments determines which code path executes. Procedures improve code reusability and reduce the need to repeat identical logic in multiple places.

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

Procedures and Parameters

What Is a Procedure?

A procedure is a named block of code that performs a specific task. Defining a procedure once lets you call it many times with different inputs, avoiding code repetition.

Parameters vs. Arguments

Parameters are the variable names listed in the procedure definition. Arguments are the actual values passed when calling the procedure. Arguments are copied into parameters when the call executes.

Common Trap: Thinking a parameter change inside a procedure affects the original variable. Parameters are local copies. Modifying them does not change the argument variable in the calling code.
Exam Tip: When a procedure is called, mentally substitute each argument value into the corresponding parameter name and trace the procedure body with those values.
Big Idea 3: Algorithms & Programming
Cycle 1 • Day 8 Practice • Medium Difficulty
Focus: Procedures & Parameters

Practice Question

What is displayed after the following code runs?

PROCEDURE triple(n)
{
   RETURN n * 3
}
result ← triple(4)
DISPLAY(result)
Why This Answer?

The procedure triple receives 4 as the argument for parameter n. Inside the procedure, n * 3 = 4 * 3 = 12 is computed and returned. The returned value 12 is stored in result and displayed.

Why Not the Others?

A) 4 is the input argument, not the return value. D) 7 would be n + 3, not n * 3. B) 3 is the multiplier, not the computed result.

Common Mistake
Watch Out!

Students confuse the input parameter value with the returned value, or they mix up addition and multiplication when reading the procedure body.

AP Exam Tip

When tracing a procedure call, substitute the argument value into the parameter everywhere it appears in the body, then evaluate the expression to find the return value.

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.