The K&R C Book is touted as the book to get if you want to learn C. It is the work of Brian Kernighan and Dennis Ritchie (who created the C language). The first edition was the de facto standard for C, and the second edition is still widely read today. The K&R C book isn’t just a language book, it’s a model for good standards. Even if you don’t want to learn C, it’s still a great model for how to teach a language, as well as how to document a specification.
When I first started coding, every serious programmer told me to start here. I managed to snag a used copy eventually. My first copy was a first edition of the book. Though it was K&R C, it worked for the vast majority of tasks even with newer (at the time) compilers.
The K&R book took me from knowing nothing to being able to work with embedded systems in C. C is incredibly simple, but it is also extremely rich. The K&R book set a standard which showed what C was great at, it got you far enough to truly understand the language, and all you were left with was the computer science and the specific libraries the book didn’t include. By the time you were done, there was no question as to what the core language could and couldn’t do.
What Does It Cover?
The K&R book is a treasure because it covers the entire language specification. Very few other languages have single books which can cover the entire specification, and even fewer have decided to do so in a satisfactory way. It also covers many of the basic libraries which are required to make C useful to interact with the system. This book basically takes you to where you can use the language in full for any real task with a little topic knowledge.
It covers the basic features and functions of the language, but also includes useful examples. For instance, in the introductory tutorial section, it includes how to implement a program to count characters and another to count words (in English). The end of each section includes exercises for the reader to really reinforce the topics.
The “C Programming Language” as a Model Programming Book
Kernighan and Ritchie’s C Programming Language isn’t just a good programming book, it is a model of how technical writing should be. By including the basic structure of the language and combining it with common algorithms and use cases a real programmer would encounter, it teaches C in a way that is natural and efficient. I reread this book in preparation for the Lua book I am writing.
It breaks the language into conceptual units (like most good programming books do) such as control flow, data types, functions, etc. What makes it excel is that each, individual concept is broken down in an approachable way. For instance, if statements are introduced in the general form of if( [expression] ) { [what to do] }, then actual examples are provided. It shows how the general structure looks, then shows you how to populate each piece. The authors then furnish examples which are basic at first, then more applicable examples for actual coding exercises. They also show what not to do and why. At the end of their explanation, there really aren’t any questions as to what works and what doesn’t.
This workflow seems commonsense, but many language books fail to provide this level of clarity and proper scaffolding. C Programming Language starts by describing the usage and grammar of a given structure and details it out in the context of the language, and programming in general. Even though I love Lua, the Programming in Lua book is useless as a standalone learning manual due to the fact it does not follow this type of workflow.
Is C Still Relevant?
Almost every modern operating system is written in C or a derivative of C. The Linux kernel is written in C and many core tools are still written in C. The NT kernel for Windows is also still largely written in C as well. MacOS uses Objective-C, which is ANSI C with a new object system bolted in to write many of its application. C is still in basically everything if you look close enough.
C is also useful for embedded systems development. Many ARM microcontrollers and other boards are easiest to work with in C. C gives you the raw power to make the most use of limited resources, but enough abstraction to focus on the problem at hand. Other languages may work better for the task on more powerful controllers, but C will basically always be a good choice for anything low level.
Languages like Perl and Lua have many C-based libraries they tie in to. Even things like Python support C based libraries (though Python prefers C++ in most cases). While the K&R C book isn’t going to teach you how to do all of this, it will teach you the language enough that you only have to focus on learning to extend it for the task you’re working on.
Learning C and Learning to Learn C
This book will get you through the entire core specification of ANSI C. It teaches in a way that enables someone with virtually no programming knowledge to really get started. It doesn’t cover the compiler or anything like that though, so you’ll need to get that elsewhere. Once you’re to the point you know how to work with your compiler and toolchain, this book will take you all the way through the language as it exists on every environment.
You’ll have to learn to add the bits and pieces for a given task, but unlike C++ or many other languages, you will have the entirety of the core language in a single, concise volume. The book also teaches some basic algorithms and data structures so that you can really use the language. It teaches some basic implementations of trees and quicksort among others, though the explanations are extremely brief for these.
Even if you don’t want to learn C, this book will teach you how to learn to learn C which can be extended to other languages. It is the best current model for teaching and learning a programming language. The organization is exceptional and the depth this book manages to convey which such brevity is a standard for how technical documentation should be. This book should be on every programmer’s bookshelf even if they don’t work with C.
Get it here.