The C Programming Language by Kernighan and Ritchie
Recently, I re-discovered “The C Programming Language” by Brian W. Kernighan and Dennis Ritchie.
I first bought this book soon after it came out in 1988 and, if, like me, you are put off by 500-page volumes that promise to teach you a programming language in 24 hours, or a month, or whatever… you might like it.
Kernighan and Ritchie not only wrote the book, but Ritchie wrote the language, too. So it is nothing if not authoritative. They then went on to revise the language and produce a new edition of the book. So if your grandfather, or aging uncle, offers to lend you a copy of K&R’s first edition, just politely accept and then put it on the shelf for posterity. It’s the second edition, the ANSI version, that you need.
The K&R book is quite short — less than 300 pages — and in two main parts, the first part is a tutorial which covers the main aspects of the language and the second is a series of chapters going into the different parts of the language in much more depth.
The tutorial gives plenty of examples albeit fairly short ones and you can get a pretty good idea of the language just from these 40-odd pages. I was a professional C programmer for several years and the tutorial part was all I needed to get started.
The rest of it can act as a reference or for more in-depth reading. You will need to read this as you become more a proficient and experienced C programmer.
As Kernighan and Ritchie say in the book, C is a small language and thus does not require a large book to explain it. However, while is may be quick to learn, it takes rather longer to become proficient and it can be quite challenging to produce complex programs that might be more easily created in a higher level language such as Python.
One of the main philosophies behind C is that the programmer should be trusted to know what she is doing. Programs like Java provide certain protections against programmer errors, C doesn’t provide much protection beyond simple type-checking of data (and even that can be circumvented). For example, in Java if you declare an array of, say, 20 items, it will throw up an error if you try and set a value in the 21st element. Not so in C. The C approach is that if the programmer is writing to the 21st element he must be doing so for a reason, so let him do it.
In addition to the main parts of the book, there are two prefaces (one to the first and one to the second editions) that give a short history of C and three appendices. The first appendix is a C reference manual which provides formal definitions for all of the language constructs; the second is a description of the standard C library which provides function for file handling, input/output, maths, string handling an other useful stuff; the last appendix is of historical interest only, these days, as it gives the differences between the first and second versions of the languages.
So how good is this book? It is not a beginner’s book — it helps if you have a reasonable understanding of programming first but K&R is thought by many people to be the bible of C so if you want to know C inside out, it’s an essential book to have in your library.
C Programming Language, 2nd Edition by Brian W. Kernighan and Dennis M. Ritchie (affliate link)