Hello Coders!
I'm looking for help swapping variables with C++, I know that you can use a temporary variable but you can also do it without it. Can someone show me both ways?
[CODE lang="cpp" title="C++"]int a = 5;
int b = 10;
//I want A to 10 and B to be 5.
// I think I have an idea, is this correct?
a=a+b;
b=b-a[/CODE]
I'm looking for help swapping variables with C++, I know that you can use a temporary variable but you can also do it without it. Can someone show me both ways?
[CODE lang="cpp" title="C++"]int a = 5;
int b = 10;
//I want A to 10 and B to be 5.
// I think I have an idea, is this correct?
a=a+b;
b=b-a[/CODE]
Last edited: