Home

Tutoring

Subjects

Live Classes

Study Coach

Essay Review

On-Demand Courses

Colleges

Games


Sign up

Log in

Opening subject page...

Loading your content

Practice

  • All Subjects
  • Algebra Flashcards
  • SAT Math Practice Tests
  • Math Question of the Day
  • Live Classes
  • On-Demand Courses

Varsity Tutors

  • Find a Tutor
  • Test Prep
  • Online Classes
  • K-12 Learning
  • College Search
  • VarsityTutors.com

© 2026 Varsity Tutors. All rights reserved.

← Back to quizzes

AP Computer Science Principles Quiz

AP Computer Science Principles Quiz: Calling Procedures

Practice Calling Procedures in AP Computer Science Principles with focused quiz questions that help you check what you know, review explanations, and build confidence with test-style prompts.

Question 1 / 20

0 of 20 answered

Consider the following procedure.

PROCEDURE checkEligibility(age, hasLicense) { IF (age >= 16 AND hasLicense = true) { RETURN("Eligible to drive") } ELSE { RETURN("Not eligible to drive") } }

Which of the following procedure calls will return the string "Eligible to drive"?

Which of the following procedure calls will return the string "Eligible to drive"?

Select an answer to continue

What this quiz covers

This quiz focuses on Calling Procedures, giving you a quick way to practice the rules, question types, and explanations that matter most for AP Computer Science Principles.

How to use this quiz

Try each quiz question before looking at the correct answer. Use the explanations to review missed ideas, then come back to similar questions until the pattern feels familiar.

All questions

Question 1

Consider the following procedure.

PROCEDURE checkEligibility(age, hasLicense) { IF (age >= 16 AND hasLicense = true) { RETURN("Eligible to drive") } ELSE { RETURN("Not eligible to drive") } }

Which of the following procedure calls will return the string "Eligible to drive"?

Which of the following procedure calls will return the string "Eligible to drive"?

  1. checkEligibility(17, true) (correct answer)
  2. checkEligibility(16, false)
  3. checkEligibility(15, true)
  4. checkEligibility(true, 17)

Explanation: Correct. To return "Eligible to drive", the condition age >= 16 AND hasLicense = true must be true. In this option, age is 17 (which is >= 16) and hasLicense is true. Both parts of the AND condition are true, so the entire condition is true. The other options fail one or both parts of the condition.

Question 2

Consider the following procedure.

PROCEDURE getBonus(score) { RETURN(score * 10) }

The following code segment is executed.

finalScore ← 50 + getBonus(5) DISPLAY(finalScore)

What is displayed when the code segment is executed?

  1. 100 (correct answer)
  2. 55
  3. 500
  4. 550

Explanation: Correct. The expression getBonus(5) is evaluated first. The procedure call returns 5 * 10, which is 50. The assignment statement then becomes finalScore ← 50 + 50, which assigns 100 to finalScore. This value is then displayed. Distractor D incorrectly calculates (50 + 5) * 10. Distractor B incorrectly calculates 50 + 5. Distractor C incorrectly calculates 50 * 10.

Question 3

Consider the following procedure.

PROCEDURE showGreeting(name) { DISPLAY("Welcome, ") DISPLAY(name) }

A programmer calls the procedure with the following statement.

showGreeting("Explorer")

What is displayed as a result of executing the code?

  1. Welcome, Explorer (correct answer)
  2. Welcome, name
  3. Explorer
  4. showGreeting("Explorer")

Explanation: Correct. The procedure call passes the argument "Explorer" to the parameter name. The procedure then displays the string literal "Welcome, " followed by the value of name, which is "Explorer". The DISPLAY command adds a space after each output, resulting in "Welcome, Explorer". Distractor B incorrectly displays the parameter name instead of its value. Distractor C only shows a portion of the output. Distractor D shows the code statement itself, not its output.

Question 4

Consider the following procedure and procedure call.

PROCEDURE displayItem(name, cost, inStock) { /* implementation not shown */ }

displayItem("Laptop", 1200, true)

When the procedure displayItem is called, what value is assigned to the cost parameter?

  1. 1200 (correct answer)
  2. "Laptop"
  3. true
  4. cost

Explanation: Correct. Arguments in a procedure call are matched to parameters based on their position. The second argument in the call is 1200, which corresponds to the second parameter in the procedure definition, cost. Therefore, cost is assigned the value 1200. The other distractors represent the values assigned to the other parameters or the parameter name itself.

Question 5

Consider the following code segment.

Line 1: PROCEDURE calculate(num1, num2) Line 2: { Line 3: RETURN(num1 * num2) Line 4: } Line 5: Line 6: result ← calculate(5, 10)

In the code segment, which of the following best describes the relationship between the values 5 and 10 on Line 6 and the variables num1 and num2 on Line 1?

  1. The values 5 and 10 are arguments that are passed to the parameters num1 and num2. (correct answer)
  2. The values 5 and 10 are parameters that are passed to the arguments num1 and num2.
  3. The values 5 and 10 are variables that are used to define the procedure's parameters num1 and num2.
  4. The values 5 and 10 are return values from the procedure that are assigned to the parameters num1 and num2.

Explanation: Correct. Parameters are the variables listed in a procedure's definition (num1, num2). Arguments are the actual values (5, 10) passed to the procedure when it is called. Distractor B incorrectly reverses the terms. Distractor C incorrectly identifies the values as variables. Distractor D incorrectly describes the flow of data; values are passed into, not returned to, parameters.

Question 6

Consider the following procedures.

PROCEDURE double(val) { RETURN(val * 2) }

PROCEDURE calculate(a, b) { temp ← double(a) + b DISPLAY(temp) }

What is displayed as a result of the call calculate(5, 3) ?

What is displayed as a result of the call calculate(5, 3) ?

  1. 13 (correct answer)
  2. 16
  3. 10
  4. 8

Explanation: Correct. The procedure calculate is called with a as 5 and b as 3. Inside calculate, the procedure double is called with the argument a, which is 5. double(5) returns 5 * 2 = 10. The variable temp is then assigned the value of 10 + b, which is 10 + 3 = 13. The value of temp, 13, is then displayed.

Question 7

A programmer creates the following procedure to move a robot on a grid.

PROCEDURE makeTurn(direction, steps) { IF (direction = "left") { ROTATE_LEFT() } ELSE { ROTATE_RIGHT() } REPEAT steps TIMES { MOVE_FORWARD() } }

Which of the following procedure calls will cause the robot to turn right and then move forward 4 squares?

  1. makeTurn("right", 4) (correct answer)
  2. makeTurn(4, "right")
  3. makeTurn("right")
  4. makeTurn(right, 4)

Explanation: Correct. This call provides "right" for the direction parameter and 4 for the steps parameter. The IF condition ("right" = "left") is false, so the ELSE block executes, causing a right turn. The REPEAT loop then executes 4 times, moving the robot forward 4 squares. Distractor B provides the arguments in the wrong order. Distractor C provides too few arguments. Distractor D provides right as a variable name instead of the string literal "right".

Question 8

Consider the following procedure, which is intended to determine if a number is positive.

PROCEDURE isPositive(num) { IF (num > 0) { RETURN(true) } ELSE { RETURN(false) } }

A program uses this procedure to count the positive numbers in a list.

myList ← [-2, 0, 5, 10, -8] count ← 0 FOR EACH value IN myList { IF (isPositive(value)) { count ← count + 1 } } DISPLAY(count)

What is displayed when the code segment is executed?

  1. 2 (correct answer)
  2. 3
  3. 4
  4. 5

Explanation: Correct. The loop iterates through the list. For each element, it calls isPositive. isPositive(-2) is false. isPositive(0) is false. isPositive(5) is true, so count becomes 1. isPositive(10) is true, so count becomes 2. isPositive(-8) is false. The final value of count, which is 2, is displayed.

Question 9

Based on the provided scenario, in what order are procedures called to produce the weather report?​

  1. GenerateReport, then ComputeAverages, then FilterByDate.
  2. FilterByDate, then ComputeAverages, then GenerateReport. (correct answer)
  3. ComputeAverages, then FilterByDate, then GenerateReport.
  4. FilterByDate, then GenerateReport, then ComputeAverages.

Explanation: This question tests AP Computer Science Principles skills: understanding and calling procedures. In programming, procedures are blocks of code designed to perform a specific task; they are called within a program to execute their defined operations. In the provided scenario, procedures FilterByDate, ComputeAverages, and GenerateReport work together to produce a weather report. Data flows through these procedures via parameters and return values in a logical sequence. Choice B is correct because it accurately reflects the logical order: first filter the data to the relevant date range, then compute averages on that filtered subset, and finally generate the report from those computed values. Choice C is incorrect because computing averages before filtering would waste resources calculating values for data that will be discarded, and could produce incorrect results. To help students: Emphasize understanding the role of each procedure within the program and practice tracing data flow through parameters and return values. Encourage students to think about efficiency and logical dependencies when determining the correct order of procedure calls.

Question 10

A program is executing a sequence of statements. When a statement containing a procedure call is executed, what happens next in the flow of control?

  1. The program immediately jumps to the first line of the called procedure and executes its statements. (correct answer)
  2. The program finishes executing all remaining statements in its current block before executing the procedure.
  3. The program skips the procedure call and continues to the next statement in the sequence.
  4. The program terminates, and the called procedure begins running as a new, separate program.

Explanation: Correct. A procedure call interrupts the normal sequential execution. The flow of control transfers to the body of the called procedure. After the procedure finishes, control returns to the point immediately following the call. Distractor B describes sequential execution without a call. Distractor C is incorrect because procedure calls are meant to be executed. Distractor D incorrectly describes program termination.

Question 11

Consider the following procedure and code segment.

PROCEDURE calculate(val1, val2) { DISPLAY(val1 - val2) }

x ← 20 y ← 5 calculate(x / 2, y * 3)

What is displayed when the code segment is executed?

  1. -5 (correct answer)
  2. 15
  3. 10
  4. 5

Explanation: Correct. The arguments passed to the calculate procedure must be evaluated first. The first argument is x / 2, which is 20 / 2 = 10. The second argument is y * 3, which is 5 * 3 = 15. The procedure then assigns 10 to val1 and 15 to val2. Inside the procedure, val1 - val2 is 10 - 15, which equals -5. This value is displayed.

Question 12

Consider the following procedure.

PROCEDURE process(num) { result ← num + 5 DISPLAY(result) }

The following code is executed.

x ← 10 process(x) process(3)

What is the sequence of values displayed?

  1. 15 followed by 8 (correct answer)
  2. 15 followed by 18
  3. 10 followed by 3
  4. 15 followed by 15

Explanation: Correct. The first call is process(x), where x is 10. The procedure calculates 10 + 5 and displays 15. The second call is process(3). The procedure calculates 3 + 5 and displays 8. The variable x is not modified by the procedure call. Distractor B incorrectly assumes the value from the first call affects the second. Distractor C displays the arguments, not the results. Distractor D incorrectly repeats the first result.

Question 13

What is the primary benefit of using parameters when defining a procedure in a program?

  1. They allow the procedure to be reused with different input values, making the code more general. (correct answer)
  2. They guarantee that the procedure will execute more quickly than code written without procedures.
  3. They prevent runtime errors by automatically checking the data types of the arguments.
  4. They reduce the total number of variables needed in a program by storing all data within procedures.

Explanation: Correct. Parameters act as placeholders for data. By using parameters, a programmer can write a single procedure that can operate on a wide range of different data values passed as arguments, promoting code reuse and generalization. Distractor B is incorrect; using procedures can sometimes add a small amount of overhead and does not guarantee faster execution. Distractor C is a function of some specific programming languages (static typing), but it is not the primary benefit of parameters themselves. Distractor D is incorrect; parameters are local to the procedure and do not necessarily reduce the overall number of variables needed.

Question 14

Consider the following procedure.

PROCEDURE printPattern(symbol, count) { REPEAT count TIMES { DISPLAY(symbol) } }

What is displayed as a result of the call printPattern("*", 4)?

What is displayed as a result of the call printPattern("*", 4)?


  1. (correct answer)
  2. symbol symbol symbol symbol

    • 4

Explanation: Correct. The printPattern procedure is called with symbol as "" and count as 4. The REPEAT loop executes 4 times. In each iteration, DISPLAY("*") is executed. The DISPLAY command prints the value followed by a space, so the final output is " * * * ". Distractor C is incorrect because DISPLAY adds a space. Distractor B incorrectly prints the parameter name. Distractor D misunderstands how the procedure functions.

Question 15

Consider the following procedure.

PROCEDURE checkValue(num) { IF (num > 10) { DISPLAY("High") } ELSE { DISPLAY("Low") } }

What is displayed by the call checkValue(10)?

What is displayed by the call checkValue(10)?

  1. Low (correct answer)
  2. High
  3. High Low
  4. Nothing is displayed.

Explanation: Correct. The procedure is called with the argument 10. The condition num > 10 is evaluated as 10 > 10, which is false. Therefore, the code in the ELSE block is executed, and "Low" is displayed. Distractor B is incorrect because the condition is not met. Distractor C is incorrect because only one branch of an IF/ELSE statement can execute.

Question 16

The following code segment is intended to calculate and display a discount.

Line 1: PROCEDURE calculateDiscount(price, percent) Line 2: { Line 3: discountAmount ← price * (percent / 100) Line 4: DISPLAY(discountAmount) Line 5: } Line 6: Line 7: total ← 200 Line 8: rate ← 15 Line 9: calculateDiscount(total, rate)

In the code segment shown, which line contains the procedure call?

  1. Line 9 (correct answer)
  2. Line 1
  3. Line 3
  4. Line 4

Explanation: Correct. Line 9, calculateDiscount(total, rate), is the statement that invokes or 'calls' the procedure, passing the values of the variables total and rate as arguments. Line 1 is the procedure definition, which declares the procedure and its parameters. Lines 3 and 4 are statements inside the procedure's body.

Question 17

Consider the following procedure.

PROCEDURE subtract(a, b) { RETURN(a - b) }

What is displayed by the following statement?

DISPLAY(subtract(10, subtract(5, 2)))

What is displayed by the following statement?

  1. 7 (correct answer)
  2. 3
  3. -3
  4. 13

Explanation: Correct. The statement has a nested procedure call. The inner call, subtract(5, 2), is evaluated first. It returns 5 - 2, which is 3. The outer call then becomes subtract(10, 3). This call returns 10 - 3, which is 7. The DISPLAY statement then displays 7.

Question 18

A program contains the following procedure and code segment.

PROCEDURE updateScore(currentScore) { currentScore ← currentScore + 100 RETURN(currentScore) }

score ← 500 newScore ← updateScore(score) DISPLAY(score) DISPLAY(newScore)

What is displayed when the code segment is executed?

  1. 500 followed by 600 (correct answer)
  2. 600 followed by 600
  3. 500 followed by 500
  4. 600 followed by 500

Explanation: Correct. In AP CSP's model, arguments are passed by value. When updateScore(score) is called, a copy of score's value (500) is sent to the currentScore parameter. The procedure calculates 500 + 100 and returns 600. This return value is assigned to newScore. The original score variable is not modified. Thus, score is still 500 and newScore is 600.

Question 19

A programmer wrote the following procedure to update a value.

PROCEDURE doubleValue(x) { x ← x * 2 DISPLAY(x) }

The following code segment is then executed.

myVar ← 10 doubleValue(myVar) DISPLAY(myVar)

What is the output of the code segment?

  1. 20 followed by 10 (correct answer)
  2. 20 followed by 20
  3. 10 followed by 20
  4. 10 followed by 10

Explanation: Correct. The call doubleValue(myVar) passes the value of myVar (10) to the parameter x. Inside the procedure, x becomes 10 * 2 = 20, and 20 is displayed. Because parameters are passed by value, the original variable myVar is not affected by the change to x inside the procedure. Therefore, when DISPLAY(myVar) is executed after the call, its original value of 10 is displayed.

Question 20

Program A contains the following code.

DISPLAY("Drawing a square") /* code to draw a square / DISPLAY("Drawing a triangle") / code to draw a triangle */

Program B contains the following code.

PROCEDURE draw(shapeName) { DISPLAY("Drawing a ") DISPLAY(shapeName) /* code to draw the shape */ }

draw("square") draw("triangle")

Which of the following statements best describes an advantage of the procedure call used in Program B compared to the code in Program A?

  1. Program B uses a procedure to reduce code duplication and make the program easier to modify. (correct answer)
  2. Program B will execute faster than Program A because procedure calls are more efficient.
  3. Program B is shorter because the names of the shapes are passed as arguments to a procedure.
  4. Program B uses a procedure that allows it to draw more types of shapes than Program A can.

Explanation: Correct. Program B abstracts the action of drawing into a procedure. This avoids repeating similar blocks of code. If a change is needed (e.g., changing the display message), it only needs to be done once in the procedure definition, making the program easier to maintain and modify. Distractor B is incorrect; procedure calls can add overhead and don't guarantee faster execution. Distractor C is a possible side effect but not the primary advantage, which is about structure and maintainability, not just length. Distractor D is incorrect; both programs explicitly handle the same two shapes.