Calling Procedures MCQ Practice

Question 1 of 10

What is displayed?

PROCEDURE Double (n)
{
  RETURN (n * 2)
}
x ← Double (5)
DISPLAY (x)
  1. A. 10
  2. B. Double
  3. C. Nothing is displayed.
  4. D. 5

Question 2 of 10

Which statement is best?

PROCEDURE Banner (msg)
{
  DISPLAY (msg)
}
result ← Banner ("hi")
DISPLAY (result)
  1. A. result stores hi because DISPLAY returns that text.
  2. B. Banner has no RETURN, so result does not receive a usable returned value from the procedure.
  3. C. The call is illegal because procedures cannot have parameters.
  4. D. Both displays show nothing.

Question 3 of 10

Values displayed in order?

PROCEDURE Add (a, b)
{
  RETURN (a + b)
}
DISPLAY (Add (2, 3))
DISPLAY (Add (4, 1))
  1. A. 7 then 5
  2. B. 3 then 1
  3. C. 5 then 5
  4. D. 2 then 3

Question 4 of 10

Arguments are passed as values. What is displayed?

PROCEDURE Inc (k)
{
  k ← k + 1
  DISPLAY (k)
}
num ← 4
Inc (num)
DISPLAY (num)
  1. A. 4 then 4
  2. B. 4 then 5
  3. C. 5 then 5
  4. D. 5 then 4

Question 5 of 10

What is displayed?

PROCEDURE Max2 (p, q)
{
  IF (p > q)
  {
    RETURN (p)
  }
  ELSE
  {
    RETURN (q)
  }
}
m ← Max2 (3, 8)
DISPLAY (m)
  1. A. 8
  2. B. 11
  3. C. Max2
  4. D. 3

Question 6 of 10

In the call Area (3, 5), the values 3 and 5 are:

  1. A. Parameters defined only after RETURN
  2. B. Arguments provided by the caller
  3. C. Always ignored by PROCEDURE
  4. D. Names of local lists

Question 7 of 10

What is displayed?

PROCEDURE Half (n)
{
  RETURN (n / 2)
}
DISPLAY (Half (Half (8)))
  1. A. 8
  2. B. 4
  3. C. 2
  4. D. 1

Question 8 of 10

Which description matches the run?

PROCEDURE ShowSum (a, b)
{
  DISPLAY (a + b)
}
PROCEDURE GiveSum (a, b)
{
  RETURN (a + b)
}
x ← GiveSum (1, 2)
DISPLAY (x)
y ← ShowSum (1, 2)
DISPLAY (y)
  1. A. Both x and y store 3 because DISPLAY returns values.
  2. B. Cannot call two different procedures.
  3. C. Only one number is ever displayed.
  4. D. GiveSum returns 3 into x which is displayed; ShowSum also displays 3 inside the call, and y has no returned value from RETURN.

Question 9 of 10

Robot R faces east before the call. After TurnAround, facing?

PROCEDURE TurnAround
{
  ROTATE_LEFT
  ROTATE_LEFT
}
TurnAround
Row C1 C2
R1 W W
R2 R
  1. A. west
  2. B. north
  3. C. east
  4. D. south

Question 10 of 10

PROCEDURE Diff (x, y) { RETURN (x - y) }. Call to display 6?

  1. A. DISPLAY (Diff)
  2. B. DISPLAY (Diff (9, 3))
  3. C. DISPLAY (Diff ("x", "y"))
  4. D. Diff ← 6