CS Atlas GATE 2027
Compiler Design course
0 / 90 complete

Compiler Design/Phase 7 · Integration & Final Test

Chapter review LI.5.4 · Item 66 of 90

Parameter passing

Read at your own pace. Try the questions before opening the answers.

On this page

ACompressed recap

🧾

Value copies in; reference passes the address computed at the call (watch aliasing); value-result copies in and copies back in order on return; name re-evaluates the argument expression at every use (thunks). Trace by keeping a table of the caller’s variables and applying each rule exactly.

BMerged rule card

5.4 Parameter passing: by value, by reference, by value-result, by name; output tracing

  • Value: copy in; caller unaffected.
  • Reference: pass address (fixed at the call); aliasing possible.
  • Value-result: copy in, copy back on return to call-time locations, in order.
  • Name: re-evaluate the actual expression at every use (thunk).
  • Trace with a table of the caller’s cells.

CInterleaved GATE-style questions

Q1MCQ2 marksTrace

Program P1 of Lesson 5.4 (p(i, a[i]) with i = 0, a = {10, 20, 30}). Under call by value-result the printout is:

  • (A) 1 10 20 30
  • (B) 2 11 20 30
  • (C) 1 11 20 30
  • (D) 2 10 21 30

Q2NAT1 markAliasing

For int a = 1; void q(int x, int y) { x = x + 10; y = y * 2; }, what is a after q(a, a) by reference?

Numerical answer: ________

Q3NAT1 markAliasing

Same, by value-result:

Numerical answer: ________

Q4MCQ1 markDefinition

Which mode evaluates the actual parameter every time the formal is used?

  • (A) value
  • (B) reference
  • (C) value-result
  • (D) name

Q5MCQ2 marksTrace

With int x = 3; int f(int y) { x = x + 1; return y + x; }, main prints f(x) then x. By reference:

  • (A) 7, 4
  • (B) 8, 4
  • (C) 7, 3
  • (D) 8, 3

Q6MSQ2 marksTrace

For the same program, which modes print 7 as the first number?

  • (A) value
  • (B) reference
  • (C) value-result
  • (D) name

Q7MCQ1 markLanguages

A Pascal var parameter or a C++ reference parameter is passed:

  • (A) by value
  • (B) by reference
  • (C) by name
  • (D) by value-result

Q8NAT2 marksTrace

For P6 (a = 2, f(a, a) with x = x + y; y = x * y; print(x, y)), what is the first printed x under call by value?

Numerical answer: ________

Answer Vault

Try the questions first. Open when you are ready to check.

Q1 Answer: (C)2 marks

Computed: 1 11 20 30.

  • (A) is wrong: Value.
  • (B) is wrong: Reference.
  • (D) is wrong: Name.

Re-read: Lesson 5.4 — Parameter passing: by value, by reference, by value-result, by name; output tracing

Q2 Answer: 221 mark

a = 11, then a = 22: 22.

Re-read: Lesson 5.4 — Parameter passing: by value, by reference, by value-result, by name; output tracing

Q3 Answer: 21 mark

x = 11, y = 2; copy back x then y: 2.

Re-read: Lesson 5.4 — Parameter passing: by value, by reference, by value-result, by name; output tracing

Q4 Answer: (D)1 mark

Thunks re-evaluate it.

  • (A) is wrong: Once, at the call.
  • (B) is wrong: Address once, at the call.
  • (C) is wrong: Once at the call and once at return.

Re-read: Lesson 5.4 — Parameter passing: by value, by reference, by value-result, by name; output tracing

Q5 Answer: (B)2 marks

y is x: x becomes 4; 4 + 4 = 8; x is 4. Computed: 8, 4.

  • (A) is wrong: Value.
  • (C) is wrong: Value-result.
  • (D) is wrong: x stays 4.

Re-read: Lesson 5.4 — Parameter passing: by value, by reference, by value-result, by name; output tracing

Q6 Answer: (A) (C)2 marks

y keeps the copy 3 under value and value-result.

Re-read: Lesson 5.4 — Parameter passing: by value, by reference, by value-result, by name; output tracing

Q7 Answer: (B)1 mark

The formal is an alias of the actual.

  • (A) is wrong: No copy is made.
  • (C) is wrong: No re-evaluation.
  • (D) is wrong: No copy-back.

Re-read: Lesson 5.4 — Parameter passing: by value, by reference, by value-result, by name; output tracing

Q8 Answer: 42 marks

x = 2 + 2 = 4.

Re-read: Lesson 5.4 — Parameter passing: by value, by reference, by value-result, by name; output tracing

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.