What's the Output of This Program?

David Geary dmg at ssc-vax.UUCP
Sat Jul 9 02:07:19 AEST 1988


  Well, I've grown tired of "Fortran vs. C", and the discussion of NULL that's
been draaaaaaaaaaaaaging on in this newsgroup, so here's something a little
different...
  Here's a quiz I give my Introductory C class on the first day ;-)

  What's the output of this program?


#define  NUM_STRINGS  6

static char *Strings[NUM_STRINGS] = { "Project",
                                      "Make",
			              "Add",
			              "Builtin",
			              "Success",
			              "Filer\n "
                                    };
char **Yuck = Strings;

char *Putchar(c)
  char *c;
{
  putchar(*c); 
  return c;
}

main()
{
  char *Ptr;
  char *Putchar();

  Putchar((Putchar(Ptr = &**Yuck)) + 2);
  Putchar(Putchar((&**(Yuck += 3) + 5)) + 1);
  Putchar(Putchar((Yuck[-3] + 6)) - 2); 
  Putchar(Putchar(&**(Yuck += 2) + 4) + 2);
  Putchar(Putchar((Ptr = &**(Yuck = Strings + 1))) + 1);
  Putchar(Putchar(&**(Yuck+1)+1));
  putchar(*(&**(Yuck+2)+ strlen(*(Yuck+2))-1));
  Putchar(Putchar(Putchar(&**(Yuck+3) + 4) + 1) + 1);
  Putchar(&**(Yuck + 4) + strlen(*(Yuck + 4)) -  2);
}

  Of course, for all you seasoned C vets out there, this will be no
problem.  Anybody else have a more convoluted example than this?


                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  ~ "...They don't give a damn,		  ~
                  ~     about no trumpet playin' band	  ~
                  ~     It aint what they call  	  ~
                  ~     rock and roll..."		  ~
                  ~					  ~
                  ~	      Sultans of Swing            ~
                  ~               Dire Straits            ~
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


-- 
***********************************************************
* David Geary, Boeing Aerospace Co., Seattle, WA 	  *
* I disclaim all disclaimers....			  *
***********************************************************



More information about the Comp.lang.c mailing list