Answers to the exercises in The Practice of Programming

I read the book The Practice of Programming and worked all the exercises.

I bought the book shortly after it was published in 1999, on sort of a whim after reading a Slashdot review. I don't think I even read the whole book. I didn't appreciate at the time how much it had shaped my programming style. One thing that sticks in my mind is this technique for getting the number of elements in an array:

#define NELEMS(a) (sizeof(a) / sizeof(a[0]))
That alone was worth the price.

Doing all the exercises was challenging! It took me 10 months, with several spacious breaks. I think it was harder than The C Programming Language. The exercises in the first chapter are there to trick you into thinking the rest will be as easy. Here are a few difficult ones:

That last one, though challenging, was one of my favorites.

These solutions are dedicated to waffle, the 120 MHz Fujitsu Lifebook laptop computer on which I did almost all the work.


Back Answers for The C Programming Language