130k views
4 votes
Which of the following comments would be the best post-condition for this swap function? void swap( int& left, int&right);

A. //Postcondition: None
B. //Postcondition: the values of left and right are exchanged.
C. //Postcondition: left has the value of right
D. //Postcondition: left and right are unchanged

User Glubus
by
8.3k points

1 Answer

7 votes

Final answer:

The best post-condition for the swap function is that the values of left and right are exchanged.

Step-by-step explanation:

The best post-condition for the swap function would be option B: //Postcondition: the values of left and right are exchanged.

This means that after calling the swap function, the values of the left and right variables will be swapped. For example, if left initially had the value 5 and right initially had the value 10, after calling swap(left, right), left will have the value 10 and right will have the value 5.

User IjzerenHein
by
7.9k points