Showing posts with label swap variables. Show all posts
Showing posts with label swap variables. Show all posts

Swap two variables without create any third temp variable

Wednesday, April 14, 2010

            int a = 2;
            int b = 3;
           
            a = b + a;         // a is 5
            b = a - b;         // now b is 2
            a = a - b;         // now a is 3

            Console.Write("a = ");
            Console.WriteLine(a);
            Console.Write("b = ");
            Console.WriteLine(b);
            Console.ReadLine();


**************************LINKS******************************

I have created a new better blog:

My Youtube channel:

**************************LINKS******************************