Hey.
Can anyone tell me why we need pointers when swapping varibles such as:
void swap (int *x, int *y)
{
int temp;
temp = *x;
*x =*y;
*y = temp;
}
int x=12, y=4
swap (&x,&y);
why would they swap values, as opposed to using...
void swap (int x, int y)
{
int temp;
temp = x;
x =y;
y = temp;
}
...where the x and y value won't swap?
Can anyone tell me why we need pointers when swapping varibles such as:
void swap (int *x, int *y)
{
int temp;
temp = *x;
*x =*y;
*y = temp;
}
int x=12, y=4
swap (&x,&y);
why would they swap values, as opposed to using...
void swap (int x, int y)
{
int temp;
temp = x;
x =y;
y = temp;
}
...where the x and y value won't swap?
Comment