interesting program
ark at alice.UUCP
ark at alice.UUCP
Sun Jan 31 00:59:12 AEST 1988
In article <19 at berick.UUCP>, jeffl at berick.UUCP writes:
> What does the following program print? (I know of at least one
> program that prints the wrong answer).
> {
> int k = 4;
> k = k++;
> printf("and the answer is %d\n", k);
> exit(0);
> }
Saying "the wrong answer" implies that there is a right answer.
In fact, the result of this program is undefined, because the
implementation is permitted to
fetch k
increment k
store old value of k in k
(in which case the result is 4), or
fetch k
store old value of k in k
increment k
(in which case the result is 5).
More information about the Comp.lang.c
mailing list