Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
22 lines (11 sloc) 1.82 KB

K&R Examples and Exercises

This is a collection of the examples and exercises in The C Programming Language Book, Second Edition (or K&R book).


I note the section and page that each example is taken from at the top of the file in a comment. The examples in the book are not numbered or labeled in any way. My naming convention is simply SECITON-NUMBER.c (section being the section of the book and number be the order that the example appeared in that section).


Exercises are named as they are labeled in the book. (If an exercise instructs you to write more than one version of something, they will be suffixed with the number.) Some of the exercises (like ones that instruct you to think about something) are omitted. I note the section and page that the exercise is take from, as well as the exercise instructions at the top of the file in a comment.

There are quite possibly better solutions to the exercises than what I have written, as I'm not super proficient in C (yet!). I figure if I type all of the examples and work all of the exercises, I'll be pretty decent at C by the end of the book (and hopefully improved my typing skills as well).


The book doesn't add brackets for one line control structures, /* */ style comments, and some brackets silliness. This drives me nuts. I have tweaked them for my own sanity, so examples may vary slightly in appearance from those in the book. Their functionality will be identical.


Feel free to do whatever you want with any of this. It's mainly for my own learning, but I figured I'd share. The example code is probably copy written by the authors of the book. Hopefully I'm not breaking any laws by posting it.