On Sep 15, 11:10 am, CM Saikanth Varma <[email protected]>
wrote:
> The answer is indeed 56.
> Explanation: Increment operator has highest priority
> so (i++)*(i++) will be evaluated as
> (7)*(8)=56
> This is valid only in C
>

I don't have the final c99 standard available, this is from the draft:

5.1.2.3 Program execution

2 Accessing a volatile object, modifying an object, modifying a file,
or calling a function
that does any of those operations are all side effects,11) which are
changes in the state of
the execution environment. Evaluation of an expression may produce
side effects. At
certain specified points in the execution sequence called sequence
points, all side effects
of previous evaluations shall be complete and no side effects of
subsequent evaluations
shall have taken place. (A summary of the sequence points is given in
annex C.)

The following are the sequence points described in 5.1.2.3:
— The call to a function, after the arguments have been evaluated
(6.5.2.2).
— The end of the first operand of the following operators: logical AND
&& (6.5.13);
logical OR || (6.5.14); conditional ? (6.5.15); comma , (6.5.17).
— The end of a full declarator: declarators (6.7.5);
— The end of a full expression: an initializer (6.7.8); the expression
in an expression
statement (6.8.3); the controlling expression of a selection statement
(if or switch)
(6.8.4); the controlling expression of a while or do statement
(6.8.5); each of the
expressions of a for statement (6.8.5.3); the expression in a return
statement
(6.8.6.4).
— Immediately before a library function returns (7.1.4).
— After the actions associated with each formatted input/output
function conversion
specifier (7.19.6, 7.24.2).
— Immediately before and immediately after each call to a comparison
function, and
also between any call to a comparison function and any movement of the
objects
passed as arguments to that call (7.20.5).


6.5 Expressions

2 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.(71)

71) This paragraph renders undefined statement expressions such as
i = ++i + 1;
a[i++] = i;
while allowing
i = i + 1;
a[i] = i;


A legal compiler can produce 49,56,42,or marizipan flowers. The result
of the expression is undefined. You should NEVER code crap like this,
EVER. It should make you break out in a cold sweat and run screaming
from the room.

--
Geoff

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to