Pointers

This very short, very confusing program shows the type of code that programmers who become addicted to pointers in C can write. It also is an excellent exercise in using pointers; if you can read this and figure out what it prints, you will be able to read and understand (almost) any use of C pointers! This exercise is from Alan Feuer's marvelous book The C Puzzle Book.

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 );
}

ECS 30-A, Introduction to Programming
Spring Quarter 2002
Email: cs30a@cs.ucdavis.edu