-1

i am using following code in selection sort program for swap the value.When i pass arguments like swap(a[min],a[j]) It swaps the values but doesn't increment the "swaps" variable. But when i pass arguments like swap(&a[min],&a[j]) It swaps the value as well as increment the "swaps" variable. I didn't get what is happening under the hood.
I am using minGW compiler.

void swap(int *x,int *y)
{
swaps++;
int temp;
temp=*x;
*x=*y;
*y=temp;

}

1 Answers1

6

When you use swap(a[min],a[j]), you are most likely calling std::swap. Another reason to avoid

using namespace std;
R Sahu
  • 204,454
  • 14
  • 159
  • 270