#include <stdio.h>
#include <iostream>
usingnamespace std;
void swap(void *a,void *b)
{
void* temp;
temp =a;
a=b;
b=temp;
}
int main()
{
int *a,*b;
int c=8;
int d=9;
a=&(c);
b=&(d);
printf("C: a is %d ,b is %d \n",*a,*b);
// cout<<"C++: a is "<< (*a) <<" b is "<< (*b) <<endl;
swap(a,b);
printf("C: a is %d ,b is %d \n",*a,*b);
// cout<<"C++: a is "<< (*a) <<" b is "<< (*b) <<endl;
}
It happens because your swap function doesn't actually do anything, it just moves the local variables around.
When you include <iostream>, std::swap is called instead of your function.