Parameters and the values passed in a call

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Parameters and the values passed in a call

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. In PROCEDURE Show(Num : INTEGER), what is Num?
A A parameter: a name that holds the value given in the call
B The value 5 that is passed in the call
2. Given PROCEDURE Show(Num : INTEGER), what does Num hold after CALL Show(5)?
A Show
B 5
3. Which statement is true about calling the same procedure twice: CALL Greet(3) then CALL Greet(8)?
A The parameter holds 3 in the first call and 8 in the second
B The parameter must be renamed before the second call
4. Which call correctly supplies a value from a variable called Score to PROCEDURE Show(Num : INTEGER)?
A CALL Show(Num : Score)
B CALL Show(Score)
5. Which is a valid way to give a value to PROCEDURE Show(Num : INTEGER)?
A CALL Show(2 + 3)
B CALL Show(Num) (when Num has not been declared in the main program)

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1PROCEDURE Greet(Name : STRING) AA definition needs a parameter name and type, such as Num : INTEGER, not a fixed value. The value 5 belongs in the call.
2CALL Greet("Ava") BThe call includes the parameter name and data type, which belong in the definition. A call should give a value such as 5.
3The same procedure can be called with different values, so the parameter holds a different value each time CThe value "Ava" is given to the procedure, so the parameter Name holds "Ava" while it runs
4A variable can supply the value in a call, and the parameter holds that variable's current value DName is a parameter: a name in the definition that will hold the value given in the call
5CALL Show(Num : INTEGER) ECALL Show(5) CALL Show(9)
6PROCEDURE Show(5) OUTPUT 5 ENDPROCEDURE FScore ← 40 CALL Show(Score)

Definitions

parameter

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
PROCEDURE Show(___ : INTEGER) OUTPUT Num ENDPROCEDURE
2.
Score ← 8 CALL Show(_____) // Num holds 8 while Show runs
3.
Count ← 4 CALL Show(Count _ 2) // Num holds 8 while Show runs
4.
PROCEDURE Double(Num : INTEGER) OUTPUT ___ * 2 ENDPROCEDURE
5.
CALL Show(2) CALL ____(7) // Same procedure, new value in the call

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A PROCEDURE Greet(Name : STRING)
B OUTPUT "Hello ", "Name"
C ENDPROCEDURE
D CALL Greet("Sam")
Question 2
A PROCEDURE Show(Num : INTEGER)
B OUTPUT Number * Number
C ENDPROCEDURE
D CALL Show(4)
Question 3
A PROCEDURE Show(5 : INTEGER)
B OUTPUT Num
C ENDPROCEDURE
D CALL Show(5)
Question 4
A PROCEDURE Add(A, B : INTEGER)
B Total ← A + B
C OUTPUT Sum
D ENDPROCEDURE
E CALL Add(2, 3)
Question 5
A PROCEDURE Show(Num : INTEGER)
B OUTPUT Num
C ENDFUNCTION
D CALL Show(5)

Answer Key

Parameters and the values passed in a call
Section A: Quick Questions
Q1
A — A parameter: a name that holds the value given in the call
Q2
B — 5
Q3
A — The parameter holds 3 in the first call and 8 in the second
Q4
B — CALL Show(Score)
Q5
A — CALL Show(2 + 3)
Section B: Match the Pairs
Q1
PROCEDURE Greet(Name : STRING) → Name is a parameter: a name in the definition that will hold the value given in the call
Q2
CALL Greet("Ava") → The value "Ava" is given to the procedure, so the parameter Name holds "Ava" while it runs
Q3
The same procedure can be called with different values, so the parameter holds a different value each time → CALL Show(5) CALL Show(9)
Q4
A variable can supply the value in a call, and the parameter holds that variable's current value → Score ← 40 CALL Show(Score)
Q5
CALL Show(Num : INTEGER) → The call includes the parameter name and data type, which belong in the definition. A call should give a value such as 5.
Q6
PROCEDURE Show(5) OUTPUT 5 ENDPROCEDURE → A definition needs a parameter name and type, such as Num : INTEGER, not a fixed value. The value 5 belongs in the call.
Section C: Definitions
Q1
parameter — A name in the subroutine definition that holds the value given in the call while it runs. With PROCEDURE Show(Num : INTEGER), CALL Show(5) makes Num hold 5.
Section D: Fill in the Blanks
Q1
PROCEDURE Show(Num : INTEGER) OUTPUT Num ENDPROCEDURE
Q2
Score ← 8 CALL Show(Score) // Num holds 8 while Show runs
Q3
Count ← 4 CALL Show(Count * 2) // Num holds 8 while Show runs
Q4
PROCEDURE Double(Num : INTEGER) OUTPUT Num * 2 ENDPROCEDURE
Q5
CALL Show(2) CALL Show(7) // Same procedure, new value in the call
Section E: Spot the Error
Q1
B — Name is the parameter, so it must not be in quotes. With quotes the program prints the word Name instead of the value in the call. It should be OUTPUT "Hello ", Name.
Q2
B — The parameter in the definition is called Num, not Number. Number does not exist, so the line fails. It should be OUTPUT Num * Num.
Q3
A — The definition needs a parameter name, not a value. The value 5 is given later in the CALL. It should be PROCEDURE Show(Num : INTEGER).
Q4
C — The sum was stored in Total, and Sum was never created. The line should be OUTPUT Total.
Q5
C — A procedure must end with ENDPROCEDURE. ENDFUNCTION is only used to close a function.