0
How do you exchange the value of a variable to another variable like the value of variable a will go to variable b in C#?
I need a hand
2 Answers
+ 4
Which language? Typically looks something like var a = var b, but exact form may depend on the language.
+ 3
In Python it is very easy:
a,b = b,a
In most other languages, you need a temporary variable, to store the value of one, so it won't get lost.
eg if a=1, b=2:
tmp = a // a=1, b=2, tmp=1
a = b // a=2, b=2, tmp=1
b = tmp // a=2, b=1, tmp=1 swapped