ISRO Computer Science (CSE) 2009 - Question 58

All ISRO Computer Science (CSE) papers | ISRO Computer Science (CSE) 2009

Consider the following code written in a pass-by-reference language... subroutine swap(ix, iy)... call swap(ia, ib+5)... print ia, ib

  • A. 13, 8
  • B. 8, 3
  • C. 13, 3
  • D. 8, 13

Answer: A. 13, 8

Explanation: With pass-by-reference, the expression 'ib+5' evaluates to 8 (temp location). Swap exchanges ia (3) and temp (8). ia becomes 8? Wait. \nia=3, ib=8. Call swap(ia, 13). ix refers to ia, iy refers to temp(13). \nSwap: ia becomes 13, temp becomes 3. \nResult: ia=13, ib=8. (ib is not changed). Output 13, 8.

| | All questions of ISRO Computer Science (CSE) 2009