Question 50Asked in UGC NET Computer Science, August 2016 (Paper II & III, Selected Questions)

Assume that the program 'P' is implementing parameter passing with 'call by reference'. What will be printed by following print statements in P?

Assume that the program 'P' is implementing parameter passing with 'call by reference'. What will be printed by following print statements in P? Program P( ) { x = 10; y = 3; funb (y, x, x); print x; print y; } funb (x, y, z) { y = y + 4; z = x + y + z; }
  1. A10, 7
  2. B31, 3
  3. C10, 3
  4. D31, 7
Show answerHide answer

Correct answer: (B) 31, 3

Explanation

Inside funb( ), x refers to y of main, and both y and z refer to x of main. y = y + 4 makes main's x = 14. z = x + y + z = 3 + 14 + 14 = 31, which is stored in main's x. main's y is unchanged (3). Printed output is 31, 3.

From UGC NET Computer Science PYQ, August 2016 (Paper II & III, Selected Questions)

This is question 50 of UGC NET Computer Science PYQ, August 2016 (Paper II & III, Selected Questions). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.