1. ## Problem with pointers

Hi, I am having the following problem. Assume the code:

int i = 4, j = 7;
int *p = &i, *q = &j;
i = (*p)++ + *q;

After that, variable i will take value 12, right? Now, assume the following modification:

int i = 4, j = 7;
int *p = &i, *q = &j;
i = (*p)++ * *q;

Following the same reasoning, variable i would be equal to 29.

However, using gcc (linux), variable i is equal to 5 in both cases!!! Under windows, I get 12 and 18, respectively!

Does anyone know why???

2. If we remove the pointers, first snippet is effectively equivalent to:
Code:
```int i = 4, j = 7;
i = i++ + j;```
The second snippet is effectively equivalent to:
Code:
```int i = 4, j = 7;
i = i++ * j;```
So, in both cases i is read twice and modified within consecutive sequence points. This results in undefined behaviour.

3. Thanks!
Let me see of I got it. The sufix operator ++ modifies i only after solving the expression, but the value of i is read before solving.

4. Originally Posted by thennecy
Let me see of I got it. The sufix operator ++ modifies i only after solving the expression, but the value of i is read before solving.
No. Take a look at this series of FAQs: C Expressions.