- Feb 13, 2001
- 83,769
- 19
- 81
Pseudo code:
#define int swap(a,b) a=a-b;b=b-a;a=a-b;
int main()
{
int x = 5 ; int y =10;
swap(x,y);
printf("%d %d\n",x,y);
swap2(x,y);
printf("%d %d\n",x,y);
}
int swap2(int a, int b)
{
temp=a;
b=a;
a=temp;
return 0;
}
now it returns:
10 5
10 5
it appears swap is built into C++ as the define and swap2 can be changed to whatever I'd like (#define swap(a,b) with nothing else and make swap2 as 'return 0;' and nothing else) and get:
10 5
10 5
anyone want to explain this if it's not just a built in function?
Thanks
Å
#define int swap(a,b) a=a-b;b=b-a;a=a-b;
int main()
{
int x = 5 ; int y =10;
swap(x,y);
printf("%d %d\n",x,y);
swap2(x,y);
printf("%d %d\n",x,y);
}
int swap2(int a, int b)
{
temp=a;
b=a;
a=temp;
return 0;
}
now it returns:
10 5
10 5
it appears swap is built into C++ as the define and swap2 can be changed to whatever I'd like (#define swap(a,b) with nothing else and make swap2 as 'return 0;' and nothing else) and get:
10 5
10 5
anyone want to explain this if it's not just a built in function?
Thanks
Å