+13 votes
2.2k views

Consider the following function

void swap(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}  

In 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

asked
edited | 2.2k views

## 4 Answers

+20 votes
Best answer

ans (D).

option A will not swap the values because it is passed by value...

option B will not swap the value

  void swap(int a, int b) in which arguments will not take address because its value not pointer

option C is false , given reason is wrong

and option D is correct .. we cant use $swap(x,y)$ because it is pass value function call which will not swap the values

answered by Veteran (14.5k points)
edited by

This Might Give Clear Understanding

+8 votes
I think, option D will be answer.

Because in the given function, parameters are used as passed by value.So there will be no change in actual parameters which is defined under the main function..
answered by Veteran (25.8k points)
Yes option D should be correct.
–1 vote
ans d)
answered by Boss (5.1k points)
–2 votes

Ans: D swap (x, y) cannot be used as the parameters are passed by value

answered by Boss (7.8k points)
Answer:

+6 votes
6 answers
1
+4 votes
3 answers
2
+1 vote
0 answers
3