# Thread: what is the difference between them..

1. ## what is the difference between them..

what is the difference between them..
*(p++) and *(++p)

2. Whether there is a net difference depends on context. What do you think is the difference?

3. i think there is no difference
in both cases it points to the next address

i gives the value of the next cell

4. Originally Posted by transgalactic2
i think there is no difference
Observe the output of this program and draw your conclusions:
Code:
```#include <stdio.h>

int main(void)
{
int numbers[2] = {1, 2};

int *p = numbers;
printf("%d\n", *(p++));
printf("%d\n", *p);

p = numbers;
printf("%d\n", *(++p));
printf("%d\n", *p);

return 0;
}```

5. it against the logic of cols

i used that the cols are separating
so the part inside the cols are separated from the operation outside the cols.
but here
Code:
`printf("%d\n", *(p++));`
it returns the value inside p goes to printf and then return back to the cols and increases the address by 1.

why???

it should be like an onion
do whats inside the cols the go outside
like in if statement

if ((a)&&(b)) etc..
i evaluates "a" and "b" anf then compares them like onion

??

6. Originally Posted by transgalactic2
it returns the value inside p goes to printf and then return back to the cols and increases the address by 1.

why???
The result of p++ is p. Therefore, the result of *(p++) is *p. The increment is a side effect. Incidentally, *(p++) is equivalent to *p++.

7. so *(p++) says
first do the operation outside and then go back and increase p by 1
correct?

8. Originally Posted by transgalactic2
so *(p++) says
first do the operation outside and then go back and increase p by 1
correct?
No, it says "first take the current value of p, then increment p" and then look at the address of the expression.

--
Mats

9. "first take the current value of p, then increment p" and then look at the address of the expression."

"first take the current value of p"

means go with the first value to the printf

then "increment p"
correct?

10. What *(p++) means, is this:

Increment the position in memory that p points to, so, if it originally pointed to element 25 of an array, increment p to point to element 26. However, since the ++ is on the right side, increment it *after* accessing the memory. *(++p) is slightly different.

Example program:

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

int main() {
int array[5] = {0, 2, 4, 6, 8};
int *p = &array[1];
printf("%i\n", *(p++));
printf("%i\n", *p);
return 0;
}```
Example program output:

Code:
```2
4```
However, another example, this time for *(++p):

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

int main() {
int array[5] = {0, 2, 4, 6, 8};
int *p = &array[1];
printf("%i\n", *(++p));
printf("%i\n", *p);
return 0;
}```
The output this time is

Code:
```4
4```