Click here to Skip to main content
12,407,037 members (62,854 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked

Cost Reduced Swap

, 8 Dec 2006
Rate this:
Please Sign up or sign in to vote.
Swapping in C++


void main() 
    int i=10,j=20; 

Here the two variables are swapped in a single statement . The cost is reduced than the known swapping methods.

  • Temporary variables are not used.
  • addition and subtraction only.
  • can be used for any data types and this is efficient than the normal methods.
  • time is saved.
  • space is saved.
  • complexity reduced.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

India India
i am an Computer Engineering student from india

You may also be interested in...

Comments and Discussions

GeneralTradeoff between efficiency and maintainability Pin
Harold Bamford12-Dec-06 7:46
memberHarold Bamford12-Dec-06 7:46 
Questionwhat about asm ? Pin
bruno leclerc11-Dec-06 22:35
memberbruno leclerc11-Dec-06 22:35 
Questionwhat about asm ? Pin
bruno leclerc11-Dec-06 22:33
memberbruno leclerc11-Dec-06 22:33 
GeneralThe "classic" way Pin
Luca Piccarreta11-Dec-06 3:49
memberLuca Piccarreta11-Dec-06 3:49 
GeneralNot Guaranteed to Work Pin
ricecake11-Dec-06 3:23
memberricecake11-Dec-06 3:23 
Generalexpression is evaluated from left to right Pin
jeyakumarrr10-Dec-06 23:24
memberjeyakumarrr10-Dec-06 23:24 
Generalit will work in Turbo C& C++ compiler only Pin
jeyakumarrr10-Dec-06 23:23
memberjeyakumarrr10-Dec-06 23:23 
GeneralDoes not work! Pin
z33z10-Dec-06 6:29
memberz33z10-Dec-06 6:29 
Generalit will work for all data types.. Pin
jeyakumarrr9-Dec-06 22:48
memberjeyakumarrr9-Dec-06 22:48 
Generalcheck it out in the system and say Pin
jeyakumarrr9-Dec-06 22:42
memberjeyakumarrr9-Dec-06 22:42 
QuestionUndefined behaviour? Pin
david_dawkins9-Dec-06 14:22
memberdavid_dawkins9-Dec-06 14:22 
GeneralIt doesn't work Pin
Vindicator6669-Dec-06 3:45
memberVindicator6669-Dec-06 3:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160730.1 | Last Updated 9 Dec 2006
Article Copyright 2006 by jeyakumarrr
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid