OOPS
August 29, 2024OOPS
August 29, 2024OOPS
|
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) only
|
|
|
(b) only
|
|
|
(c) only
|
|
|
(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.
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.
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.
