PrepGo

AP Computer Science Principles Practice Quiz: Calling Procedures

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Test your understanding with short quizzes. This quiz has 16 questions to check your progress.

Question 1 of 16

According to the provided content, what is the definition of a procedure?

All Questions (16)

According to the provided content, what is the definition of a procedure?

A) A single line of code that performs a calculation.

B) A named group of programming instructions that may have parameters and return values.

C) A variable that stores input from the user.

D) The sequential execution of statements in a program.

Correct Answer: B

Content point 2 explicitly states, 'A procedure is a named group of programming instructions that may have parameters and return values.'

In the context of a procedure, what is the difference between a parameter and an argument?

A) There is no difference; the terms are interchangeable.

B) A parameter is the value returned by a procedure, while an argument is the value it receives.

C) A parameter is an input variable in the procedure's definition, while an argument is the actual value passed to the procedure when it is called.

D) An argument is a procedure's name, while a parameter is the set of instructions inside the procedure.

Correct Answer: C

Content point 4 clarifies this distinction: 'Parameters are input variables of a procedure. Arguments specify the values of the parameters when a procedure is called.'

Consider the following code segment: 1. x ← 10 2. Greet("World") 3. x ← 20 PROCEDURE Greet(name) { DISPLAY("Hello") DISPLAY(name) } What is the order of execution for the statements in this program?

A) Line 1, Line 2, Line 3, then the Greet procedure statements.

B) The Greet procedure statements, then Line 1, Line 2, and Line 3.

C) Line 1, then the Greet procedure statements, then Line 3.

D) Line 1, Line 2, then the Greet procedure statements, then Line 3.

Correct Answer: C

Content point 5 states that a procedure call interrupts sequential execution. The program executes line 1. Then, the call on line 2 interrupts the flow, causing the statements inside the Greet procedure to execute. After the procedure completes, flow of control returns to the statement immediately following the call, which is line 3.

Which of the following terms is mentioned in the content as another name for a procedure?

A) Variable

B) Argument

C) Function

D) Loop

Correct Answer: C

Content point 3 states, 'Procedures are referred to by different names, such as method or function, depending on the programming language.'

Consider the following procedure: PROCEDURE Calculate(num1, num2) { result ← num1 * num2 RETURN(result) } Which code segment correctly calls this procedure and stores its result in a variable named 'product'?

A) product ← Calculate(5, 10)

B) Calculate(5, 10) → product

C) product = Calculate(num1, num2)

D) RETURN Calculate(5, 10) TO product

Correct Answer: A

Content point 9 provides the notation for assigning a returned value from a procedure call to a variable: result ← procName(arg1, arg2, ...). Option A matches this format exactly.

What is the primary effect of a procedure call on the program's flow of control?

A) It permanently stops the program's execution.

B) It restarts the program from the beginning.

C) It skips the procedure's code and continues to the next line.

D) It interrupts the sequential execution to run the procedure's statements before continuing.

Correct Answer: D

Content point 5 explicitly states, 'A procedure call interrupts the sequential execution of statements, causing the program to execute the statements within the procedure before continuing.'

Consider the following code segment: PROCEDURE Double(value) { RETURN(value * 2) } x ← 5 y ← Double(x) DISPLAY(y) What is displayed as a result of executing this code?

A) 5

B) 10

C) y

D) value * 2

Correct Answer: B

First, x is assigned 5. Then, the Double procedure is called with the argument 5. Inside the procedure, 5 * 2 is calculated, which is 10. The RETURN statement sends the value 10 back. This returned value is then assigned to y. Finally, DISPLAY(y) displays the value of y, which is 10.

According to the exam reference sheet notation, what is the purpose of the INPUT() procedure?

A) To display a value to the user.

B) To define the input variables (parameters) for another procedure.

C) To accept a value from the user and return that value.

D) To check if a user's input is valid.

Correct Answer: C

Content point 10 describes the INPUT() procedure: it 'accepts a value from the user and returns the input value.'

What is the role of the `RETURN(expression)` statement within a procedure?

A) It displays the value of the expression to the screen.

B) It re-runs the procedure from the beginning with a new expression.

C) It returns the flow of control to the calling statement and sends back the value of the expression.

D) It assigns the value of the expression to a global variable named 'RETURN'.

Correct Answer: C

Content point 8 states that the `RETURN(expression)` statement 'returns the flow of control and the value of the expression.' This means it ends the procedure's execution and provides a value back to where the procedure was called.

Consider the following code segment: PROCEDURE Process(a, b) { c ← a + b RETURN(c) } result1 ← Process(3, 4) result2 ← Process(result1, 2) DISPLAY(result2) What is displayed when this code is executed?

A) 7

B) 5

C) 9

D) 11

Correct Answer: C

First, `Process(3, 4)` is called. Inside the procedure, c becomes 3 + 4 = 7. The value 7 is returned and assigned to `result1`. Next, `Process(result1, 2)` is called, which is `Process(7, 2)`. Inside the procedure, c becomes 7 + 2 = 9. The value 9 is returned and assigned to `result2`. Finally, `DISPLAY(result2)` displays the value 9.

In the procedure call `CalculateArea(10, 20)`, what are the values 10 and 20 referred to as?

A) Parameters

B) Arguments

C) Return values

D) Variables

Correct Answer: B

Content point 4 states that 'Arguments specify the values of the parameters when a procedure is called.' The values 10 and 20 are the specific values being passed into the procedure during the call.

A program needs to get a number from the user and then display a message including that number. Which of the following code segments correctly accomplishes this using the provided procedures?

A) DISPLAY(INPUT())

B) userNum ← INPUT() DISPLAY("Your number is ", userNum)

C) INPUT(userNum) DISPLAY(userNum)

D) DISPLAY(RETURN(INPUT()))

Correct Answer: B

Content point 10 states INPUT() returns the value entered. Content point 9 shows how to assign this returned value to a variable (`result ← procName(...)`). Content point 7 shows how to display a value. Option B correctly calls INPUT(), assigns the returned value to `userNum`, and then uses `DISPLAY` to show the result.

After a procedure finishes executing its last statement, what happens to the program's flow of control?

A) The program terminates.

B) The procedure is automatically called again.

C) Control returns to the statement immediately following the procedure call.

D) Control returns to the very first line of the program.

Correct Answer: C

Content point 5 explains the flow of control: 'Flow of control returns after the last statement (or a return statement) is executed.' This means the program resumes its sequential execution from where it left off.

Consider the following procedure: PROCEDURE IsPositive(num) { IF (num > 0) { RETURN("Yes") } ELSE { RETURN("No") } } What is the result of executing the statement `DISPLAY(IsPositive(-5))`?

A) The text "Yes" is displayed.

B) The text "No" is displayed.

C) The value -5 is displayed.

D) An error occurs because DISPLAY cannot be used with a procedure call.

Correct Answer: B

The procedure `IsPositive` is called with the argument -5. Inside the procedure, the condition `num > 0` (-5 > 0) is false. Therefore, the ELSE block is executed, and the procedure returns the string "No". This returned value is then passed directly as an argument to the `DISPLAY` procedure, which displays "No".

Which statement best describes the relationship between a procedure call and the sequential execution of a program?

A) Procedure calls are executed only after all other sequential statements are finished.

B) A procedure call is an interruption of sequential execution.

C) Sequential execution and procedure calls happen at the same time.

D) A procedure call replaces the need for sequential execution.

Correct Answer: B

Content point 5 directly states, 'A procedure call interrupts the sequential execution of statements, causing the program to execute the statements within the procedure before continuing.'

A programmer defines a procedure `UpdateScore(currentScore, pointsToAdd)`. In one part of the program, they write the call `newScore ← UpdateScore(playerScore, 100)`. Which statement is the most accurate description of this interaction?

A) The parameters `playerScore` and `100` are used to define the `UpdateScore` procedure.

B) The procedure call passes the arguments `playerScore` and `100` to the parameters `currentScore` and `pointsToAdd`, and the return value is assigned to `newScore`.

C) The arguments `currentScore` and `pointsToAdd` are assigned the values of the parameters `playerScore` and `100`.

D) The procedure `UpdateScore` is called, and the variables `currentScore` and `pointsToAdd` are created and assigned the values of `playerScore` and `100`.

Correct Answer: B

This question combines several concepts. Content point 4 distinguishes parameters (in the definition, `currentScore`, `pointsToAdd`) from arguments (in the call, the value of `playerScore`, `100`). Content point 9 describes how the returned value is assigned to a variable (`newScore`). Option B correctly identifies the arguments, the parameters they correspond to, and the assignment of the return value.