For the following C program:swap(int x, int y){ int temp;temp=x;x=y;y=temp;}main(){int x=2;y=3;swap(x,y);}After calling swap, what are the values x & y?

Showing Answers 1 - 17 of 17 Answers

Sachin Chakote

  • Jul 22nd, 2005
 

The values of x and y will be same since there scope is local the swapping done inside swap() function is not reflected inside main(). 
 

  Was this answer useful?  Yes

shanmugam

  • Jul 25th, 2005
 

x=2 
y=3

  Was this answer useful?  Yes

vaseef

  • Nov 10th, 2006
 

here the question it self has syntax error.swap (int x, int y) is required.. in question swap(int x,y) is given.If we correct the line and execute the pgm , the values will not be swapped in main().so values will be x=2;y=3;

  Was this answer useful?  Yes

KALAI

  • Jan 27th, 2007
 

answerthe value of x and y will be d same because the swap() doesn't have a return statement.......

  Was this answer useful?  Yes

here the value of x=2 and y=3...as in it does not change because here only the values are passed as arguments....for the values to get changed a referece to the variables  has to be passes as an argument

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions