1. ## swap function

why this function doesnt works like this:
Code:
```void swap2 (int *c, int *d){
int g;
g=*c;
c=d;
*d=g;
}```
and not works like this:
Code:
```void swap2 (int *c, int *d){
int g;
g=*c;
c=d;
*d=g;
}```
I was thinking that both of them should work? And now I cannot find out why?

2. You need to dereference c and d when you assign d to c, since you want to change whatever they point to. Both c and d are local to the function so changing them inside swap doesn't affect what is outside it.

3. Aren't both of them the same?
c=d; /* you meant *c = *d */

4. c=d; simply sets the address in c to the address in d. Not going to change much.
Remember that they're pointing to the values that we want to swap. So we must tell the compiler that we want to change the value c is pointing to to the value d is pointing to.

5. Code:
```void swap2 (int *c, int *d){
int g;
g=*c;
c=d;
*d=g;
}```
Pointers point to something.

So line;

c=d;
makes the c pointer point to whatever d points to.

And then, you do

*d=g;
and since c points to d, it will point to HIS value, not value you wanted because the value of *d is now g.