Question: ```
#include<stdio.h>

void foo(int*);
int main()
{
    int i = 97, *p = &i;
    foo(p);
    printf("%d ", *p);
    getch();
}

void foo(int *p)
{
    int j = 2;
    p = &j;
    printf("%d ", *p);
}

```

Output is 2 97
Why not 2 2 ?
pointer p holds the address of j now so why 97 is printed ?

Answer: 
```
p = &j;

```

just changes the value of the local variable `p`. This has no effect on the caller's `p` variable (because `p` was passed by value) or the variable that `p` previously pointed to (because you didn't indirect through it). If you want to change the caller's data, write:

```
*p = j;

```
Go through the above code line by line. Here I have written comments as control passes through each of the lines...

```
#include<stdio.h>

void foo(int*);
int main()
{
    int i = 97, *p = &i;   //Lets assume i has address 2000  
    foo(p);                //p contains 2000 which is passed to foo. go to foo at 1.
    printf("%d ", *p);    // when control comes back no change to p it 
                          //still points to 2000 which stores 97 
    getch();
}

void foo(int *p) 1: // in foo another local variable p is created. 
                   //Let's call this lp. lp has now address 2000. i.e lp 
                   //and p both point to i but one locally exists in a 
                   // function and will be destroyed when control comes out 
                   // of the function 
{
    int j = 2;
    p = &j;        // now local p i.e lp points to another var j 
                   //  address. Suppose lp has address 3000 now.  
    printf("%d ", *p);  //val at address in lp is 2
}

```