May 1, 2011 at 2:26am UTC
Didn't work, throwing me errors for invalid conversion.
May 1, 2011 at 2:37am UTC
You don't want any of the * besides the one after the ints. And I'm assuming you want to swap the pointers, not the data they are pointing to.
May 1, 2011 at 2:57am UTC
Which ones, bc I've tried every combo, and nothing works..
May 1, 2011 at 3:00am UTC
A more copy-and-pasteable version of firedraco's answer.
1 2 3 4 5 6 7
/*Ignore This Code
void swap(int* a, int* b)
{
int* temp = a;
a = b;
b = temp;
}*/
Be sure to review pointers.
Last edited on May 1, 2011 at 3:38am UTC
May 1, 2011 at 3:05am UTC
What's the output?
*Edit - also, line 21 should give the compiler something to complain about.
Last edited on May 1, 2011 at 3:14am UTC
May 1, 2011 at 3:23am UTC
i = 10 j = 20
*ip = 10 *jp = 20
i = 20 j = 20
*ip = 20 *jp = 20
where it should be 10 and 20 for the third line and 20 and 10 for the 4thjavascript:editbox1.editPreview()
May 1, 2011 at 3:32am UTC
So you want to swap what the pointers are pointing at then?
1 2 3
int tmp = *i;
*i = *j;
*j = tmp;
Oh, and that stray ; won't actually give any issues, it'll just be a null statement (useless, but not harmful).
Last edited on May 1, 2011 at 3:32am UTC
May 1, 2011 at 3:33am UTC
Ah obvious oversight, sorry. You'll want to be passing references to the pointers if you want to swap them that way. Alternatively, look at the post above, or use
std::swap
1 2 3 4 5 6
void swap(int *& a, int *& b)
{
int * temp = a;
a = b;
b = temp;
}
Last edited on May 1, 2011 at 3:40am UTC
May 1, 2011 at 4:39am UTC
Yeah that didn't work either, no worries. This was for an assignment, so I was limited