-4

According to standard c why it j= i++ * i++ undefined and j=i++ & i++ perfectly legal statement?

Marc B
  • 348,685
  • 41
  • 398
  • 480
Deepak Uniyal
  • 89
  • 3
  • 14

3 Answers3

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
  • 138,975
  • 15
  • 262
  • 325
1
j= i++ * i++ ;

j=i++ & i++ ;

Both are undefined because changing the i value between sequence points

Read Why are these constructs undefined behavior?

Community
  • 1
  • 1
Gangadhar
  • 9,880
  • 3
  • 29
  • 50
  • 1
    Your 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.