Einzelnen Beitrag anzeigen

Benutzerbild von DP News-Robot
DP News-Robot

Registriert seit: 4. Jun 2010
15.671 Beiträge
 
#1

Swap two integers without using a temporary variable

  Alt 2. Okt 2021, 15:20
Here's a clever little algorithm you can use to swap two integers without using a temporary variable.

I rediscovered this tip, by Muhammad Saied, while reviewing my Delphi Tips micro-site.

Dunno why, but I find this strangley pleasing!

Assume we have two integers, A & B, both of which have values assigned. Swap their values like this:

<div style="text-align: left;">
  Mit Zitat antworten Zitat