Hi, I am getting this error:
"ERROR -: Function 'swap' must return a value' to function main"
But it does rerturn a value, the temp value to main to swap the values.
I have never come across this error, but I am 100% sure my logic is correct.
Here is the code:
Code:#include <iostream>
using std::cout;
using std::endl;
using std::cin;
int swap ( int *ptr1, int *ptr2 );
int main ( void )
{
int x = 5, y = 10;
cout << "Value of x before swap: " << x << endl
<< "Value of y before swap: " << y << endl;
swap ( &x, &y );
cout << "\nValue of x after swap: " << x << endl
<< "Value of y after swap: " << y << endl;
cin.get();
return 0;
}
int swap ( int *x, int *y )
{
int temp = *x;
*x = *y;
*y = temp;
}