Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Fortran
tmp = a
a = b
b = tmp

tmp needs to be a variable of the same type as a and b. This also works when a, b, and tmp are multidimensional arrays.
subroutine swap(a, b)
  integer, intent(inout) :: a, b
  integer :: temp
  temp = a
  a = b
  b = temp
end subroutine swap
procedure swap(a, b: in out Integer)
is
    temp : Integer;
begin
    temp := a;
    a := b;
    b := temp;
end swap;

New implementation...
programming-idioms.org