Multiple choice

Consider the following C function void swap (int a, int b) { int temp; temp =a; a =b; b =temp; } In the order to exchange the values of two variables x and y .

  1. call swap (x,y)

  2. call swap (&x,&y)

  3. swap (x,y) cannot be used as it does not return any value

  4. swap (x,y) cannot be used as the parameters are passed by value

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Here the function takes the arguments by value.

$\rightarrow$       Option (A) sends parameter by value but only the local variable a & b will be exchanged but not the actual variables x & y so incorrect. $\rightarrow$ Option (B) is incorrect sending address of x & y . $\rightarrow$ Option (C) swap (x,y) is usable there is no need to return. $\rightarrow$ Option (D) is the opposite statement of option (A), it says that the values are passed by value so won't swap so the option is correct.