Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How can we swap the values of 2 integer variables without using temp variable?

user-image
Question added by ibrahim mohsen , Project Manager , Integrant Egypt
Date Posted: 2014/05/22
عبد الرحمن أحمد عبد المنعم أحمد
by عبد الرحمن أحمد عبد المنعم أحمد , Army Engineer , Egyptian Armed Forces

//swapping x and y

x = x + y;

y = x - y;

x = x - y;

Nanak Singh Saggu
by Nanak Singh Saggu , Vice President - PROJECTS , SAGGU ENGINEERS

Using the XOR swap algorithm

ibrahim mohsen
by ibrahim mohsen , Project Manager , Integrant Egypt

Good, any other solution? :D

More Questions Like This