Will the right side of the expression get evaluated first or the left ?
void main ()
{
int i = 0 , a[3] ;
a[i] = i++;
printf ("%d",a[i]) ;
}
Will the right side of the expression get evaluated first or the left ?
void main ()
{
int i = 0 , a[3] ;
a[i] = i++;
printf ("%d",a[i]) ;
}
The order of evaluation of the operands of the assignment operator is unspecified: the operands may be evaluated in any order.
However, this expression (a[i] = i++
) yields undefined behavior because you both modify i
(using i++
) and you separately read i
(using a[i]
) without a sequence point in between those actions.
C does not define which side gets evaluated first. The standard states (C99 §6.5/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 accessed only to determine the value to be stored
The aforementioned result you posted is thereby UB.