0

Possible Duplicate:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…)
Why does sizeof(x++) not increment x?

Here the value of i is 5 but it should be 6 or 7 I guess. What's the reason?

int main(void){
    int i=5,j;
    j=sizeof(i++ + ++i);
    printf("%d %d",i,j);
}
Community
  • 1
  • 1
Shekhar
  • 55
  • 6
  • For your pleasure: [why not to use `void main`](http://stroustrup.com/bs_faq2.html#void-main) – chris Jul 24 '12 at 04:38
  • 3
    I think this was closed for the wrong reason. Although `i++ + ++i` is undefined behaviour when evaluated, it is not evaluated here, since it's the argument of `sizeof`. Since the type of the expression is `int`, the line `j=sizeof(i++ + ++i);` sets `j` to `sizeof(int)` and does not modify `i`. – Daniel Fischer Jul 24 '12 at 10:36

0 Answers0