+ 3
I need guidance for this Swap function
This is my code. I want to swap the original values of A and B. #include <iostream> using namespace std; void Swap (int A, int B); int main() { int A=1; int B=2; cout<<A; Swap(A,B); cout<<A; return 0; } void Swap (int A, int B) { int cup; cup = A; A = B; B = cup; }
2 Respuestas
+ 3
You are making copies, use a reference instead by adding & after the data type:
void Swap(int& A, int& B){/**/}
and don't forget to do the same in the prototype.
+ 11
use the second, but pass A and B as reference:
void Swap( int &A, int &B )