-4

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

Marc B
  • 356,200
  • 43
  • 426
  • 500
Deepak Uniyal
  • 89
  • 3
  • 16

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
  • 142,963
  • 15
  • 272
  • 331
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
  • 10,248
  • 3
  • 31
  • 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.