Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!ut-sally!husc6!cca!mirror!hpwalf!hpwala!hpwale!jollyc From: jollyc@hpwale.HP.COM Newsgroups: comp.lang.c Subject: Re: weird c code/ c test Message-ID: <770001@hpwale.HP.COM> Date: Tue, 4-Aug-87 15:27:41 EDT Article-I.D.: hpwale.770001 Posted: Tue Aug 4 15:27:41 1987 Date-Received: Sat, 8-Aug-87 01:15:15 EDT References: <1089@gilsys.UUCP> Organization: HP Waltham Division Lines: 65 / hpwale:comp.lang.c / mc68020@gilsys.UUCP (Thomas J Keller) / 12:17 am Jul 29, 1987 / > I just had a strange experience today. I went to see a head hunter about >an opening she wanted me to consider, and she popped this "C test" on me. >Most of it was pretty straight forward, but the last question on the test >was a **BITCH**. See if you can determine the output of this program >without actually compiling it: >#include >char *c[] = { "ENTER", "NEW", "POINT", "FIRST" }; >char **cp[] = { c+3, c+2, c+1, c }; >char ****cpp = cp; ^^^^ |||| one too many * than intended? >main() >{ > printf("%s", **++cpp); > printf("%s ", *--*++cpp+3); > printf("%s", *cpp[-2]+3); > printf("%s\n", cpp[-1][-1]+1); >} > > (actually, the program AS PRESENTED probably wouldn't have compiled, as > the *c declaration was as follows: Actually I think it does compile > char *c[] = { "ENTER", "NEW", "POINT", "FRIST", }; > > ) > > NOTE: as I entered it here, it *DOES* compile, and the output is fairly > humorous. > > I do question this as a test, however. That is some pretty esoteric >pointer manipulation there! What do you think? > >-- >Tom : The conservatives always grouse about "Law & Order" when the liberals >Keller : break the law...when the Reagan Admin. does it, it's PATRIOTISM! > >UUCP : {ihnp4,ames,qantel,sun,amdahl,lll-crg,pyramid}!ptsfa!gilsys!mc68020 >BITNET : ptsfa!gilsys!mc68020@ames.com >---------- From Kernighan & Ritchie p. 89, " Pointers have been lumped with the goto statement as a marvelous way to create impossible-to-understand programs. This is certainly true when they are used carelessly, and it is easy to create pointers that point somewhere unexpected. With discipline, however, pointers can also be used to achieve clarity and simplicity. " That is quite a tough test. Not very palatable, indeed. Jolly Chen (hplabs!hpwU> l novalie