Skip to main content
Home
Live to Learn!

Main navigation

  • Home
  • Learn
    • FoxPro
    • MS-DOS
    • C PRG
    • Java
    • ASP
    • Ruby on Rails
    • ASP.NET
    • E-Books
    • Exam Preparation
    • Tools
  • Blog
  • Forums
  • Contact
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Forums
  3. Programming
  4. Desktop Programming

Swap two variables

By Karthik , 9 January, 2011

stuartjems Wrote: Hey all
I have one problem and i am trying to find solution of that .
"swap two variables without using third temporary variable"
If anyone know then please let me know!

Following methods available:
I had tested some of the methods below in C, C++.
But, nothing works in vb.
1)
a^=b^=a^=b

2)
a = a # b
b = a @ b
a = a @ b
(Not works in C)
3)
In Ruby
a,b = b,a
4)
In PHP
list($a, $b) = array($b, $a);

5) javascript
[a, b] = [b, a]

6)
a = a + b
b = a - b
a = a - b

7)
In C / C++
a += b;
b = a - b;
a = a - b;

8)
a = a + b - (b = a);

source: stackoverflow.com

If you find anything works in VB, post below.

Forums
Desktop Programming
Profile picture for user Charles Elena

Charles Elena

13 years 6 months ago

I think you can try this one.

I think you can try this one. You can do using Xor function.a = a Xor bb = a Xor ba = a Xor b Do write function and rest of the things.

  • Add new comment

Featured Blog Posts

Convert Currency in Number to Words (Indian Rupees) - MS Excel
Foxpro Tutorial and Programs
Convert Currency in Number to Words in MS Word
Convert Currency in Number to Words (Indian Rupees) - Version 2
Best way to Use Rupee Symbol in Windows – Easy steps
Convert Currency in Number to Words - MS Access
Creating All in One Windows XP DVD with all Important Applications
RSS feed

© 2009-2025 Live to Learn.In

Terms of Use | Privacy Policy