tricky thing

Discussion in 'Web Design & Programming' started by edijs, Jun 14, 2007.

  1. edijs

    edijs Programmer

    Likes Received:
    9
    Trophy Points:
    38
    okay, um, can anyone tell me how one can exchange the values of two variables without using a temporary variable? :(
     
  2. edijs

    edijs Programmer

    Likes Received:
    9
    Trophy Points:
    38
    not tricky after all...

    Code:
    Program 1uzd;
    
    Var a,b:integer;
    
    Begin
    
    a:=1;
    b:=2;
    
    a:=a+b;
    b:=a-b;
    a:=b-a;
    
    
    end.
    
    apologees :doh:
     
  3. Addis

    Addis The King

    Likes Received:
    91
    Trophy Points:
    48
    Why would you want to do that? The C++ STL has swap() which is optimised for your architecture. I guess this one of those "Do it without the obvious way" things.
     

Share This Page