The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+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 in Compiler Design by Veteran (69k points)
edited by | 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)


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

33,646 questions
40,193 answers
114,176 comments
38,664 users