How to Swap two numbers without a Temp variable?

How to swap two numbers without a temp variable.

We can swap like below

void main() {
  
 int a=6;
  int b=9;
   swap(a,b);
}

void swap(a,b)
{
  print("Before swap : a=$a and b=$b");
  a=a+b;
  b=a-b;
  a=a-b;
  print("After swap : a=$a and b=$b");
}

 

 

This will print output like below

Before swap: a=6 and b=9

After swap: a=9 and b=6

 

 

 


Subscribe For Daily Updates

Flutter Questions
Android Questions