Code:
```\*It is assumed that the addresses of the
variables i, j and the first element of the integer array num in hexadecimal are
22FF6C, 22FF68, 22FF40 respectively.*\

int i, j = 3;
int *pi = &i, *pj = &j;
int num[5]={25, -1, 3, 12, 100};
printf("%x, %x, %x\n", &i, &j, num);
printf("%x, %x\n", pi, pj);
j++;
*pj *= 3;
printf("%x, %d\n", pj, *pj);
pi = num;
num[0] += 5;
printf("%x, %d\n", pi, *pi);
printf("%x, %d\n", pi+j, *pi+j);
*pj = *pj - 8;
printf("%x, %d\n", pj, *pj);```
What is the printed in the last line. I understand that it is 4 for %d buy don't understand the address. I thought it is 22FF72 because if j=3's Address is 22FF68 then we add 4 and get 22FF72. But why is 22FF68 is the solution?

2. You are asking why the compiler is placing certain variables at certain addresses. The answer is "Because it does."

It's no more mysterious than the fact that my favorite color is blue. Coulda' been red, coulda' been green. But it's blue. Just the way it is.

3. pj is, was, and always has been 22FF68 according to your note at the top. Since you do not change it, the computer does not change it on its own volition; it stays what it is.

4. Originally Posted by tabstop
pj is, was, and always has been 22FF68 according to your note at the top. Since you do not change it, the computer does not change it on its own volition; it stays what it is.

But isn't j=pj=4 so the address value will change? At the top, it is 3.

5. j is three, then four, then twelve. pj is, was, and will always be 22FF68. No statement in the program changes pj, so how could it change?

6. Originally Posted by tabstop
j is three, then four, then twelve. pj is, was, and will always be 22FF68. No statement in the program changes pj, so how could it change?
If it was *pj then would it have made a difference?

7. Originally Posted by Air
If it was *pj then would it have made a difference?
Go back to your code. In any statement you care to point at, whatever operation you have in mind, it already was *pj in your code. Asking what would be different if you used *pj doesn't make any sense, since you wouldn't change anything.

8. Also you need to think for five seconds what the word "address" means. If you have a house at 17 Main Street, and you tear it down and build one that is three times bigger, does your address suddenly become 51 Main Street?

9. Ah, thanks. It makes sense.

10. Originally Posted by Air
But isn't j=pj=4 so the address value will change? At the top, it is 3.
Code:
```j = *pj;
j != pj;```

11. If I was just given:

Code:
`int i=2`
Would *i equal the address of i?

Code:
```int i=2
*pi = &i```
Would pi give address of *pi which also is address of i. Also, would that mean that pi=*i?

12. Originally Posted by Air
If I was just given:

Code:
`int i=2`
Would *i equal the address of i?
don't confuse the name of a memory location with its contents; i is an int and there's no *i.
Originally Posted by Air

Code:
```int i=2
*pi = &i```
Would pi give address of *pi which also is address of i.
yes, in a nutshell
Originally Posted by Air
Also, would that mean that pi=*i?
again there is no *i; the variable is i and its contents are accessible directly as i and indirectly as *pi.

13. Thanks for all the help so far.

Furthermore, these two lines are below the codes on my first post:
Code:
```printf("%x, %d\n", pi+num[2], *(pi+num[2]));
printf("%x, %d\n", num+5, *(pi+*pj));```
What value of num[2] is considered?

EDIT: For *(pi+num[2]), what values are used? I thought it would have been 30+3 = 33 but it's 12.

14. Originally Posted by Air
Thanks for all the help so far.

Furthermore, these two lines are below the codes on my first post:
Code:
```printf("%x, %d\n", pi+num[2], *(pi+num[2]));
printf("%x, %d\n", num+5, *(pi+*pj));```
What value of num[2] is considered?

EDIT: For *(pi+num[2]), what values are used? I thought it would have been 30+3 = 33 but it's 12.
where do you think pi points to? you're adding the contents of num[2] to pi and then dereferencing it not the other way around.

15. The content of num[2] is 3, isn't it?