According to standard c why it j= i++ * i++
undefined and j=i++ & i++
perfectly legal statement?
Asked
Active
Viewed 680 times
-4

Marc B
- 356,200
- 43
- 426
- 500

Deepak Uniyal
- 89
- 3
- 16
-
4Both are undefined. Did you mean, `j=i++ && i++ `? – Mysticial Oct 22 '13 at 18:07
-
*According to the Standard* could you please provide chapter and verse? – ouah Oct 22 '13 at 18:10
-
Actually my friend got this question from some coaching institute but I found something confusing in it so posted. – Deepak Uniyal Oct 22 '13 at 18:21
3 Answers
4
They are both undefined behavior.
j = i++ * i++; // undefined behavior
j = i++ & i++; // undefined behavior
The value of object i
is modified more than once between two sequence points in the two examples.

ouah
- 142,963
- 15
- 272
- 331
1
j= i++ * i++ ;
j=i++ & i++ ;
Both are undefined because changing the i value between sequence points
-
1Your link is tagged *C++* many of the concepts are different since *C++* now has *sequenced before and after* a good *C* question would be [Why are these constructs undefined behavior?](http://stackoverflow.com/questions/949433/why-are-these-constructs-undefined-behavior). – Shafik Yaghmour Oct 22 '13 at 18:15
1
As the Mystical and ouah already said, both are undefined.
j = i++ && i++;
would be well-defined, since && short-cuts, which means, it must evalutate the left operand first, and then - if the left operand was true - the right operand.
-
3`i++ && i++` is defined not because of short-cut but because `&&` operator introduces a sequence point after the evaluation of the first operand. – ouah Oct 22 '13 at 18:13
-
-