UGC NET CS 2018 JUNE Paper-2
December 1, 2023
UGC NET CS 2018 JUNE Paper-2
December 1, 2023
UGC NET CS 2018 JUNE Paper-2
December 1, 2023
UGC NET CS 2018 JUNE Paper-2
December 1, 2023

UGC NET CS 2018 JUNE Paper-2

Question 5
Given below are three implementations of the swap( ) function in C++ :

Which of these would actually swap the contents of the two integer variables p and q ?
A
(a) only
B
(b) only
C
(c) only
D
(b) and (c) only
Question 5 Explanation: 
Module -(a) is call by value , so by using that code w can not swap the contents.
Module -(b) is call by reference , So the modification of content in the function reflects the changes in the main program. Swapping is done in the module -(b).
Module -(c) is passing addresses as parameters but in the functions definition , We are changing the addresses not the content So swapping of the values can’t be done.
Correct Answer: B
Question 5 Explanation: 
Module -(a) is call by value , so by using that code w can not swap the contents.
Module -(b) is call by reference , So the modification of content in the function reflects the changes in the main program. Swapping is done in the module -(b).
Module -(c) is passing addresses as parameters but in the functions definition , We are changing the addresses not the content So swapping of the values can’t be done.

Leave a Reply

Your email address will not be published. Required fields are marked *