Your code violates the C standard, which says:

"Between the previous and next sequence point an object shall have its
stored value modified at most once by the evaluation of an expression.
Furthermore, the prior value shall be read only to determine the value
to be stored."

Regarding postfix increment operators, the standard also states that
"The side effect of updating the stored value of the operand shall
occur between the previous and the next sequence point." Updating x in
your example does not necessarily occur before the next time x is
used.

The results of code that violates the C standard are compiler-
dependent.

Dave

On Aug 28, 6:35 am, jagadish <jagadish1...@gmail.com> wrote:
> I ran this code..
>
> int main() { int x=5;
> printf("%d",(x++ + ++x + x++));
>
> }
>
> The output printed was 18 instead of 19.. Should it not be 19?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to