OOPS

August 29, 2024

OOPS

August 29, 2024

OOPS

August 29, 2024

OOPS

August 29, 2024

OOPS

Question 88

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 88 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 88 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 *