1

Possible Duplicates:
twisted c++ code
FAQ : Undefined Behavior and Sequence Points

#include<stdio.h>
 int main()
 {  
       int i=7,j;
       j=(i++,++i,j*i); 
       return 0;
}

Is j=(i++,++i,j*i++); well defined ? Let me clear my doubt.

Community
  • 1
  • 1
Jagan
  • 19
  • 2
  • 2
    You guys have the same homework? Possible duplicate of [twisted c++ code](http://stackoverflow.com/questions/4187405/twisted-c-code) – wkl Nov 17 '10 at 06:44
  • 5
    Yes both `j=(i++,++i,j*i); ` and `j=(i++,++i,j*i++);` are [well defined](http://stackoverflow.com/questions/4176328/faq-undefined-behavior-and-sequence-points). – Prasoon Saurav Nov 17 '10 at 06:45
  • It has a problem, in that the average reader will not have a clue as to what is the intent of this code. Usually, if you write code that can be read by humans, it won't have issues for the compiler either. –  Nov 17 '10 at 06:45
  • It might be the same overall assignment. But the actual code (and answer) is different. This is well-defined, but "twisted" is not, because it modifies `j` twice without an intervening sequence point. – Matthew Flaschen Nov 17 '10 at 07:23

0 Answers0