On Mon, Feb 16, 2009 at 7:29 PM, e211 wrote:
>
> //The following code works and there is no way it should. Seems like a bug
> someone put in on purpose
>
> #include
> using namespace std;
>
> void swap(int *x, int *y)
> {
>int temp;
>temp = *x;
>*x = *y;
>*y = tem
--- Comment #2 from eakrohn at cs dot uiowa dot edu 2009-02-17 04:00
---
Problem fixed, didn't realize there was a built in swap that was getting
called. My mistake.
--
eakrohn at cs dot uiowa dot edu changed:
What|Removed |Added
--- Comment #1 from eakrohn at cs dot uiowa dot edu 2009-02-17 03:53
---
My concern is this function
swap(int *x, int *y){ ... }
with this function call
int x = 5, y = 7;
swap(x,y);
compiles and works just fine. But this function
swap(int *x){ ... }
with this function call
int x
temp = *x;
*x = *y;
*y = temp;
}
int main()
{
int x = 10;
int y = 20;
std::cout << x << " " << y << endl;
swap(x,y); //this compiles, runs and swaps... it shouldn't
std::cout << x << "
;
cout << x << " " << y << endl;
swap(x,y); //how does this work, there is no way this should compile
and
run and actually work
cout << x << " " << y << endl;
}
--
View this message in context:
http://www.nab