0
procedure f(var a:integer; var b:integer);

    begin 

    a:=a xor b;
    b:=a xor b;
    a:=a xor b;

    end;
Jeff Zeitlin
  • 9,773
  • 2
  • 21
  • 33
Jumaniyaz
  • 29
  • 2
  • 1
    You should be able to figure this out yourself fairly quickly by "executing" it by hand. – Jeff Zeitlin Apr 27 '18 at 12:42
  • `xor`: Exclusive or (xor) results in a value of true if and only if exactly one of the operands has a value of true. The rest of the code doesn't seem complicated so I'm not sure if I understand you correctly. Is it with the `xor` that you're struggling? – onlyphantom Apr 27 '18 at 12:46
  • 1
    What a strange close-voting: twice *too broad* and twice *primarily opinion based*? – Tom Brunberg Apr 27 '18 at 14:41
  • 1
    @onlyphantom *xor* is a btwise operator when the operands are integers – Tom Brunberg Apr 27 '18 at 14:43
  • 1
    The question is perfectly valid and @SOROMEED is spot on. – LU RD Apr 27 '18 at 21:42
  • 3
    The question's validity seems to arise from the procedure's name. I mean if it wasn't brilliantly named "f" I guess there would be no question to ask. – Sertac Akyuz Apr 27 '18 at 23:11
  • Why can't you just write a quick test app, call the function with two integer variables, and write the variables out after the call to see what it does yourself? – Ken White May 09 '18 at 12:31

1 Answers1

3

It's a common "trick" to swap the value of two variables (in this case: a, b) without using a third one.

See this topic (for C++, but it stands for any coding language) for a better and complete overview of the problem: Swapping two variable value without using third variable

git_gud
  • 649
  • 1
  • 11
  • 27