//flex table opened by JP

Click to See Complete Forum and Search --> : C++ switch numbers


rrcn
11-24-2003, 04:49 PM
how can i switch the values of 2 variables in c++?

lets say num1 is 3 and num2 is 5

i want num1 to have the value of 5 and num2 to have the value of 3.

nothing
11-24-2003, 04:54 PM
int num1 = 3;
int num2 = 5;

int temp = num1;
num1 = num2;
num2 = temp;

I know there is a function (swap() I think) that does the same thing except you won't need a temporary variable.

rrcn
11-24-2003, 04:58 PM
ok, thanks for your help.

much appreciated