Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!lll-tis!mordor!sri-spam!rutgers!bellcore!faline!ulysses!allegra!alice!ark From: ark@alice.UUCP Newsgroups: comp.lang.c Subject: Re: interesting program Message-ID: <7664@alice.UUCP> Date: 30 Jan 88 14:59:12 GMT References: <19@berick.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 25 Summary: there is no right answer In article <19@berick.UUCP>, jeffl@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).