Why this code outputs garbage value after swapping the values?

199 Views Asked by At

Take two numbers as input and swap them and print the swapped values.You do not need to print anything, it has already been taken care of. Just implement the given function.And the functions looks like this.

 pair < int, int > swap(pair < int, int > swapValues) {
         int c;
         c=swapValues.first; 
         swapValues.first=swapValues.second;
         swapValues.second=c;
         cout<<swapValues.first<<" "<<swapValues.second<<"\n";
    
         }
1

There are 1 best solutions below

0
Ralf Ulrich On BEST ANSWER

Just replace the line cout<<swapValues.first<<" "<<swapValues.second<<"\n"; with return swapValues;

As stated in your question

You do not need to print anything, it has already been taken care of.