A code segment will be used to swap the values of the variables a and b using the temporary variable temp. Which of the following code segments correctly swaps the values of a and b?
a) a to b, temp to a, b to temp
b) temp to a, a to b, b to temp
c) temp to a, a to temp, a to b
d) temp to a, b to temp, a to b

Respuesta :

Answer:

Option (b)

Explanation:

These are the right statements but the correct order would be :

temp=b;

b=a;

a=temp;

Value of b will be stored in temp variables and then value of a will be stored in b and afterwards value of temp variable to a. This is how value of a &b will be swapped. Swapping is needed in various codes many times. For example - while sorting an array, while reversing a string,etc.

Answer:
The answer is b
Explanation:

Otras preguntas

ACCESS MORE
EDU ACCESS
Universidad de Mexico