I enjoy programming puzzles, and as such I really like MaryMary's weekly Java puzzler. This weekend, while sorting out an attic bookcase I came across my old copy of the The C Puzzle Book by Alan Feuer. I got this book way back in the early eighties when I was first learning C. This book contains the memorable puzzle called Pointer Stew. If you could work out what Pointer Stew output, you really knew your pointers, arrays and operator precedence.

char *c[]={
	"ENTER",
	"NEW",
	"POINT",
	"FIRST"
};
char **cp[]={c+3,c+2,c+1,c};
char ***cpp=cp;
main()
{
	printf("%s",**++cpp);
	printf("%s ",*--*++cpp+3);
	printf("%s",*cpp[-2]+3);
	printf("%s\n",cpp[-1][-1]+1);
}
You just couldn't come up with such a complicated puzzle in Java (and that's a good thing).

Comments:

Post a Comment:
Comments are closed for this entry.

This blog copyright 2010 by plamere