Question: Why doesn't the statement 'a[i] = i++;' work in C?
Answer: The reason for this statement to throw an error (or at least doesn't work uniformly) in C is that the same variable 'i' is being modified in the right side of the assignment as well as it is being referred to in the left side of the assignment, which C standards don't allow. The reason for not allowing such a statement is to avoid the ambiguity whether to have the original 'i' in the left side as the array subscript or to have the changed value of 'i'. C by K&R says that such a statement will have unspecified behavior, whereas the C Standard simply rules this out and says that such a statement is undefined.
Sunday, June 1, 2008
Why doesn't the statement 'a[i] = i++;' work in C?
Labels:
C Language
Subscribe to:
Posts (Atom)

