Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!lll-tis!ames!rutgers!rochester!cornell!batcomputer!sun!mrd From: mrd@sun.soe.clarkson.edu (Mike DeCorte) Newsgroups: comp.lang.c Subject: Re: interesting program Message-ID: <297@sun.soe.clarkson.edu> Date: 31 Jan 88 23:33:26 GMT References: <19@berick.UUCP> Organization: Clarkson University, Potsdam, NY Lines: 41 In-reply-to: jeffl@berick.UUCP's message of 29 Jan 88 17:34:31 GMT Posting-Front-End: GNU Emacs 18.47.5 of Mon Jan 25 1988 on sun.soe.clarkson.edu (berkeley-unix) In article <19@berick.UUCP> jeffl@berick.UUCP (Jeff Lawhorn) writes: After watching all the flame wars here I decided that it was time to start one of my own ;) What does the following program print? (I know of at least one program that prints the wrong answer). main() { int k = 4; k = k++; printf("and the answer is %d\n", k); exit(0); } There is no wrong answer to this! (assuming you answer either 4 or 5) They are both right! Reread page 50 of K&R. If you have not read K&R DON'T tell people what is and is not correct. Here are the two possible interpetations. 1) rk = 4 (rk for rvlaue) put rk into lk (lk for lvalue) increment lk (value of lk = 5 now) final answer = 5 2) rk = 4 (rk for rvlaue) increment lk (value of lk = 5 now) put rk(4) into lk (lk for lvalue) final answer = 4 -- Michael DeCorte mrd@clutx.clarkson.edu mrd@clutx.bitnet