as the title suggest i like to swap two numbers but the thing is that i should not use 3rd variable that is doing the whole stuff only with 2 variables so plz any body help me out

Googling will get you the answer you are seeking, but then after you know it, don't ever use it for programming today or in the future -- use a temporary variable. Solving yesterday's problems today is useful to understand the techniques, but the solution may no longer be applicable to current systems.

By the way, "XOR swap" might be a good phrase for your search.

Swapping two variables is an easy stuff if you are using temporary variable

void swap(int& a,int& b)
{
int temp=a;
a=b;
b=temp;
}
//in C++ template
template<typename _Type>
void swap(_Type& t, _Type& t2)
{
_Type temp=t;
t=t2;
t2=temp;
}

using only the two variables requires a little maths.
check that out it might work for ints.

void swap(int& a,int& b)
{
a=a+b;
b=a-b;
a=a-b;
}

Hope you got the basic idea........... try it out.....
The XOR algorithm is another choice and probably good one ...........and its simple check that out urself. remember (A ^ B) ^ B=A :)

using only the two variables requires a little maths.
check that out it might work for ints.

void swap(int& a,int& b)
{
a=a+b;
b=a-b;
a=a-b;
}

Hope you got the basic idea........... try it out.....
The XOR algorithm is another choice and probably good one ...........and its simple check that out urself. remember (A ^ B) ^ B=A :)

The more important part is knowing when the addition and subtraction fails for integers, and how the XOR swap may fail, and how to correctly code the XOR swap. And also why this doesn't work for some other variable types.

But as I said, after you've learned these techniques, remember never[*] to use them.

The more important part is knowing when the addition and subtraction fails for integers, and how the XOR swap may fail, and how to correctly code the XOR swap. And also why this doesn't work for some other variable types.

But as I said, after you've learned these techniques, remember never[*] to use them.

#include <stdio.h>
int swap ( int *a, int *b ) {
*a ^= *b;
*b ^= *a;
*a ^= *b;
}
int main(void)
{
int a = 2, b = 3;
printf( "%d %d\n", a, b );
swap( &a, &b );
printf( "%d %d\n", a, b );
swap( &a, &a ); /* swap with itself */
printf( "%d %d\n", a, b );
return 0;
}

What do you get with the final line of output?
Is it what you expected?

A person starts out as the "Curator" and stands at the end of a field. Everyone else playing stands at the far end (distance depends upon playing area selected). The ...

I am currently working on a program to track my mile for my monthly expense report for work. Everything is working great, however, I can not for the life of ...

I am trying to understand the SynchronizedMap and I ran the below code. I get the below Output with an exception. According to my understanding the exception is caused when ...