how can this function swap value of x to y or y to x

Question is the title

1
2
3
4
5
6
7
void badswap (int x , int y)
{
   int temp = x;
   x=y;
   y=temp;
}
Last edited on
closed account (SECMoG1T)
That is what will happens when you call it in a program
You want them to be passed by reference, not by value.

http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/
Topic archived. No new replies allowed.