Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Code examples and exercises from the K&R
C
branch: master
Failed to load latest commit information.
examples
exercises Added exercise 1-16
.gitignore Updated gitignore
Readme.markdown Updated coding convention

Readme.markdown

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).

Examples

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

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).

Conventions

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.

License

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.

Something went wrong with that request. Please try again.