Back to the bookshelf

Typographic jacket · original cover not fetched

FROM THE SHARED SHELF · 2006–2026 SAMPLE

The C Programming Language

Brian W. Kernighan, Dennis M. Ritchie

73 readers recommend it across 38 discussions

Topics are model-inferred labels.

Keep it on your reading list

THE WORD OF MOUTH

What made it worth passing on?

Original Hacker News comments, in the readers’ own words.

apothegm
Database Design for Mere Mortals. The first afternoon I spent reading and puzzling through that book was worth an entire semester of computer science classes on the topic — and caused me to fall in love with relational databases. With special mentions to K&R as well as The Manager’s Path.
skydhash
The C programming language (ansi edition) - I had it before even leaning how to program properly. The explanations was so clear you could work out the examples with pencil and papers Mystical man-month and the pragmatic programmer. The former gave insight about managing a team, the other about managing yourself. Currently I’m reading: Unit Testing: Principles, Practices, and Patterns by Vladimir Khorikok Designing Data Intensive Application by Martin Kleppman And very recently completed Learning Domain-Driven Design by Vlad Khononov I think the three are quite good too
vram22
Not all of the ones below may be textbooks, sorry, but IMO they are all very good. I cut my programming teeth on some of them, and read others at different times later in my career. How to Solve It, by Georg Polya. A famous Hungarian mathematician. A text on general problem solving principles or techniques. A classic. How to Solve It by Computer, by Dromey, an AU CS professor. In the same spirit as the Polya book, but applied to iteratively working out algorithms and pseudocode for common important programming problems. The K&R C book. What to say. The Unix Programming Environment, by Kernighan and Pike. Ditto. Programming Pearls, and More Programming Pearls, by Jon Bentley. Among many other things, some clever / advanced uses of awk. Writing Efficient Programs, also by Bentley. I had mentioned it on HN earlier, and someone replied saying they had used it in real life, and it was gold. SQL for Professionals, by authors whose names I forget. The Object Primer, by can't remember who, but good. A Unix book by Kochan, IIRC. Object-Oriented Software Construction, by Bertrand Meyer, creator of the Eiffel programming language.…
roel_v
I remember reading 'The C programming language' (in the train, I even remember that) and when pointers really 'clicked' in my mind - it was when I realized that (*struct).member is the same as struct->member (I don't remember the exact page but it was one of the paragraphs on pointer syntax quite early on). Weird detail now that I think back about it after programming C++ for over 20 years, but that was just one of those moments for me.
ljosifov
Mentioned by most, still another vote for K&R "The C Programming Language" - for the sheer joy of it! It still puts a smile on my face recalling how much fun it made learning C. :-) Don't think I've read as measured and not-boring for another language since. Close to as much fun to read was maybe Steve Maguire's "Writing Solid Code". Not strictly about learning C, but the examples are all in C. (some people dislike it's K&R not ANSI C)

Also recommended in this reply

ccouzens
I've read but not written any c since learning rust. I've written some c years ago. I do feel that if I were to write more c now it would be better for me knowing rust and having a feel for designs that pass the borrow checker. Unhelpfully the only c book I've read was the k&r book. It seemed fine. Perhaps the question would be easier to answer if the reason for wanting to learn c was given (eg to contribute to existing c based project or to write embedded code)
fargle
Here's another vote for K&R. If you want to understand why C and UNIX were so successful, it comes down to simply excellent communication. And remember - no web, no internet, no WYSIWYG word processors, etc. at the time. To appreciate C properly, I think at some point you need to become a bit of a historian. Look at BCPL. Look at what assembly listings looked like or old Fortran. Read some of the very early papers from C and UNIX history. Check out Lions' commentary on UNIX. When you see a little of the problem C was invented to solve, it becomes a lot easier to understand why it is what it is. There's a lot of angst about why C allows Bad-Thing-X or doesn't have New-Fancy-Thing-Y. Nobody seems to remember what a change it brought to writing systems code. Then you can compare it to things written in modern C (C99+) and see that yes it has evolved quite nicely and can, if used correctly, be a nice application language too.
readme
I read K&R 20 years ago and today it's still the closest programming book to my heart -- yeah there's more modern choices but the exercises are unmatched, it's short, and it's one of the most fun books you'll ever read. The standards for C99, C11 are open. Look up what you don't learn in them and grab one of the other more modern suggestions from here for that, but K&R is a must have for any C programmer. You probably won't be able to put the book down if you start reading it.
Syzygies
I read the first edition of K&R when it came out, and switched to C for a computer algebra system that got me tenure as a math professor. K&R is a religious scripture, and remains the benchmark against which I measure all other programming books. It's in the same league as the aspirational SICP, and a far easier read. In college I'd programmed Fortran on punched cards. APL was like dropping acid, and I worked one summer as a commercial APL programmer, but it wasn't appropriate for what I needed. Pascal didn't quite fit either. C was in that context mind-blowing. The future had arrived! I had full access to the machine! If one is learning to become a plumber, one might not be so interested in how plumbing worked in 1840. If however, one is a herding dog, and needs serious work to avoid getting bored and destructive, reading K&R would put C in historical context. Later, as I depended on C, I bought each edition of C: A Reference Manual by Harbison and Steele, and read it as if I were studying to be a lawyer. I now program in Haskell, and wish I was equally versed in Clojure and Rust. If I were returning to C, I'd instead choose Rust. For my work, I have a free choice.
cxr
It's hard to take someone seriously or believe that they've even read the material when they say stuff like this. K&R (2nd ed.) is constantly calling out undefined behavior, etc. and gives you information you need to start out on a path to be a real stickler about the language. I spent time on my own learning C from K&R since the CS program at my school didn't expose anyone to C (or C++) during the first year. Later, in e.g. the computer architecture course or the data structures course when C was being used liberally (and sloppily), and as I was running across lots of C in the wild, I was continually frustrated by the frequency I saw people relying on common-but-undefined behavior that's explicitly identified as unsafe/unreliable in K&R. Here's my advice to the original poster:…
flohofwoe
K&R was a very interesting read for me, but not actually for the description of the C language, but because it describes why certain features in C look the way they do, and because it is also surprisingly and refreshingly critical towards the language (e.g. it basically admits that the function pointer syntax was a mistake). It also corrected my oversimplified view that C is a simple and small language simply because it is an old language, but it was already a simple and small language compared to other languages in the late 60's and early 70's 'programming language zoo'. All the code examples are deeply rooted in the 80's programmer mindset though, and are not very relevant for "modern C".
flohofwoe
The problem with K&R is that it stops at C89, while C99 almost feels like a new and much "friendlier" language (mainly because of compound literals and designated initialization). (e.g. shameless plug: https://floooh.github.io/2019/09/27/modern-c-for-cpp-peeps.h... (https://floooh.github.io/2019/09/27/modern-c-for-cpp-peeps.html)) K&R 2nd Edition is still a very good read of course, but mainly for all the little interesting details that are not directly related to the C syntax, but there really should have been a K&R 3rd Edition when C99 came around.
f1shy
Computer science: Knuth's TAOCP. And Sipser's Introduction to the Theory of Computation. Programming: SICP, K&R, and Stroustrup. Siebel's Practical common lisp. Artificial intelligence: AI a modern approach. Signals and Systems: Oppenheim's book Probability and statistics: Probability Theory: The Logic of Science by Jaynes
crossroadsguy
K&R. It was the best programming book I read. I have not read many other programming books to be honest. I couldn't finish most rather. It's been years since I even touched C and at this point I am not going back, I know; but as an Android dev I wish I could find a non-lengthy book like K&R that would expose me to Kotlin like I was exposed to C, while helping unlearn a lot of Java.
randcraw
K&R C is a minimalist introduction to the C language. And I love it for that. The book does not try to forewarn you of the myriad pitfalls inherent in C code. Nor does it delve into the language's extended API available via a plethora of internal and external libraries. What the book does do in only 228 pages is get you up and operational in C as quickly as possible. Then caveat coder. Personally, I'd like to see more minimalist CS books. I'm tired of having to surf through introductory tomes that often exceed 1000 pages. I'd rather an intro book introduce me to its concepts in as few pages as possible and put the programming advice and copious reference materials elsewhere, like online.
porpoisely
I read Freakonomics and Guns, Germs and Steel in college and was initially 'amazed' by it. Now, I see it as mass market rubbish used to influence a particular demographic. But that goes for pretty much everything really. Catcher in the Rye in high school. Carnegie's "How to Win Friends and Influence People". I think books can "change the way you think about almost everything" when you are younger, naive and idealistic. As you grow older, wiser and understand the world more, you leave those childish things behind. Also, as einstein said : "Reading, after a certain age, diverts the mind too much from its creative pursuits. Any man who reads too much and uses his own brain too little falls into lazy habits of thinking." I'm sure I'm not the only one that used reading as a crutch and a form of escapism and to waste time. But if you want a book that left an impression on me, K&R's C Programming Language is one. It showed me that a technical book can be concise, well written and enjoyable to read.
bluGill
"The C Programming Language" is a good read if you intend to write a book. It is well written so you should read it for inspiration on how to make your book good. If you want to learn C - there are plenty of resources that work just as well. The good ones cover things that didn't exist back then. (I've only read the original K&R from before ANSI, not one of the latter edition(s) so I can't comment on how up to date the latest version is)
wilsonnb
Our field is so varied that there is no good answer to this question unless you specify what you want to focus on. Some people are inevitably going to recommend The Art of Computer Programming, which hardly anyone has read and isn't that relevant to the work that 99% of us are doing. Someone will probably recommend The C Programming Language, also called K&R after the authors, but again it's not very useful unless you're going to be using a lot of C and even then I personally don't think it provides anything you can't get from guides on the internet. (I have actually read this one, but it's been a while) There are other classic textbooks that will probably be mentioned that are only useful to those in that domain. Many of us can get by without a deep understanding of algorithms and data structures, most people don't need to read a compiler book, etc, etc.…

Also recommended in this reply

mfrw
My take on some which I think should be atleast read once: 1) The unix programming environment 2) The design of the unix operating system 3) The Pragmatic Programmer 4) Programming Pearls 5) Computer Systems: A Programmers Prespective 6) K & R C 7) The art of Unix Programming. PS: I admit my bias towards systems.
pjc50
I have 2 of the 7 books of the X Window Programming Reference in that role. Apart from K&R, there are very few programming books which are worthwhile; up to about 10 years ago the ORA series were worthwhile, but nowadays especially with StackExchange it's just far better to get the one fragment of information you need in a handy searchable pasteable internet format. (Non-programming book recs: recently The Man Who Stole Portugal (non-fiction, surprisingly relevant to crypto) and The Time Of Gifts (biography, extravagantly written, requires checking wikipedia every 5 dozen words unless you have a really excellent knowledge of European history)

Also recommended in this reply

emmelaich
All in no particular order.... As a Unix systems engineer, I would choose 1. W.R. Stevens books on Unix and Tcp/ip. 2. Rochkind's Advanced UNIX Programming. 3. Most of the Unix/Linux manual pages. 4. Bash FAQ As a Unix systems programmer I would choose 1. Mythical Man Month 2. Jon Bentley's Programming Pearls. 3. K&R C and Stroustrup C++ 4. A recent Java reference and Bloch's Java Puzzlers 5. a reference and cookbook for the language of your choice -- Python, Ruby, Perl, etc. 6. Google's style guides
randcraw
I liked the first edition of K&R a lot. Today I suspect it shines most when compared to recent intro language books. It was succinct yet offered insight into both the language's design concepts and its implementation -- an introduction to software based on Strunk & White's spartan model of exposition. Given the abstract nature and swiss-army knife mission creep of today's languages, it's a rare intro PL book today that's smaller than 600 pages. (K&R 1978 fit into a mere 220.)
pjmorris
+1. I have a corner of a bookshelf reserved for everything Kernighan, e.g. both Software Tools editions, both C Language editions, The Unix Programming Environment, The Practice of Programming, The AWK Language, even a copy of The Elements of Programming Style. I, and my employers and clients, may owe more to Mr. Kernighan for his teaching and programming style, than anyone else.
satysin
Start with Programming in C or C A Modern Approach (although the latter is expensive even second hand) and learn some basic Linux. Then K&R just because everyone should read it. Grab C in a Nutshell, Understanding and Using C Pointers and C A Reference Manual for reference. Then get the Linux Programming Interface book. Okay maybe a bit overkill for a 12 year old...
protomyth
Career not life, so: K&R C (Draft ANSI Edition) - A small book that shows how you should write. Many of the examples are not really good code anymore, but it traveled and inspired. Perl Little Black Book - I needed to learn Perl and it was packed. Much like many of the ORA pocket references, except with a lot more examples. My copy is in rough shape with flags, notes, and highlights. I will have to dig it out of a box, but I had a system process and design book from a college class that I used extensively in my first decade of work. I think I internalized it all. I put the book in a crate with my K&R C book waiting for a good shelf to put it on when I get somewhere a little more permanent.
steakejjs
They are technical. Brushing up on: K&R - The C Programming Language K&P - The Unix Programming Environment K&P - The Practice of Programming Kerrisk - The Linux Programming Interface (Not light reading) Even though it is mostly review, reading code and seeing commands that K&R&P run has actually helped my workflow, code quality, etc. Highly recommend re-reading if it has been a while. Even things like variable names have noticeably improved since beginning re-reading. And, the Linux Programming Interface....is huge. There's always more to learn in there.
kabdib
"Godel, Escher, Bach" by Douglas Hopfstadter. I was in high school when it came out, and it really opened my eyes up to the field of computability. The philosophy was interesting, too. "Holy the Firm" by Annie Dillard. Not really about religion, more about our relationship to the world. A beautifully written little book. "The Making of the Atomic Bomb" by Richard Rhodes. This one works on me at several levels: The physics (which are explained well), the sheer titanic scope of the Manhattan project, and the meta-knowledge that someone was able to write a book this good. "The C Programming Language", by Kernighan and Ritchie. Probably the single most influential book on programming that I've read.
baumbart
Well thats an interesting question. Among the best is certainly "How to design Programs", http://htdp.org/ It's about Scheme. It does a better job than SICP I think, even though it still needs some endurance to get through. Generally, there are plenty of good books, you get some ideas usually by combining knowledge from different books... Even though this may sound a bit old-fashioned, simply in terms of quality and self-containedness, "The C Programming Language" by K&R is by far the best technical book I've read. You can certainly download it as PDF somewhere.

Also recommended in this reply

vram22
Can't really single out one book as the best I've read. But many come close: - Code Complete - 1st Edition. I have both Editions 1 and 2. Edition 1 is very good and has a lot of stuff worth reading and practicing. Kernighan and Pike's The Unix Programming Environment. Kernighan and Ritchie's The C Programming Language. Would have to think of other good ones, though there are sure to be some.

Also recommended in this reply

david92
If they already have some experience with high level languages, I would introduce them to K&R's C Programming Language. It does a good job of introducing some low-level topics, like pointers and memory management. I also second the books that teach using Scheme, like SICP. I think learning Lisp and C introduces many important concepts. Also, learning a web stack is very educational. Learning how a web application works (Internet protocols, server side code, databases, etc) taught me a lot.
njharman
http://en.wikipedia.org/wiki/Tao_Te_Ching The translations vary greatly. (from making it sound like new age mumbo jumbo, to mystic mumbo jumbo, to a profound philosophy), need to find one that's right for you. "The C Programming Language" by K&R (I read this very young 12-13, it's life changing aspects probably had a lot to do with my age) "The Hobbit" by J.R.R. Tolkien "Welcome to the Monkey House" by Kurt Vonnegut Jr.
malandrew
In addition to what others have said, I would add The Little Schemer to the list. It may not seem like the most practical book, but it will make you a better programmer. Beyond that, I would reiterate the following suggestions put forth by others: -- How to Design Programs (get version 2. Racket, the IDE for this book, is practically plug-and-play, so you won't waste time prepping your development environment) -- Think Python by Allen Downey (i haven't read this one, but it comes very highly recommended. the excerpts I've read show that Allen communicates the concepts very clearly) -- Eloquent Javascript (very good introduction, all examples can be done directly in the browser with the specially-made console. This eliminates the time and confusion you will experience trying to set up a development environment with other languages.) On top of those I'd also add: -- The C Programming Language by K&R (if you are interested in C) -- Dive into HTML5 (if you are interested in web development. HTML is a markup language, but you are going to need it to be able to build web stuff. This book complements Eloquent Javascript nicely) -- Land of Lisp…
pvg
http://www.c-faq.com/resources/books.html Take a look at the Amazon reviews of some of these, you'll probably find something to your liking. K&R is an important book to have on your bookshelf but the idea that it's the only or best book to learn C from is absurd. Another thing to do is scan the C FAQ and some of the online C tutorials just to get a feel for the language and where it fits in the language universe and to understand why a 'modern topic like threading' is not strictly a C topic. The C coding standard documents of various projects and organizations are also useful to give you an idea of what peoples' notions of sensible C look like - they can be surprisingly varied. Lastly, review known good code in the field you're interested in - in your case, this might be Python extensions. There aren't a lot of terribly good reasons to use C to 'hack on small Unix tools'. Your best path to learning the language is writing things that you actually need and where C is a good (or only) choice.
klocksib
Hmmm, here's a list of books I really like: Memory as a Programming Concept in C and C++ by Frenck The Design and Implementation of the FreeBSD Operating System by McKusick/Neville-Neil Learning GNU Emacs by Cameron, et al. Practical Common Lisp by Seibel The C Programming Language by K&R The C++ Programming Language Stroustrup The Design and Analysis of Algorithms by Leviten Assembly Language Programming for the IBM PC Family by Jones Essays/Collections: Hackers & Painters by PG Surely You're Joking Mr. Feynman by Feynman What Do You Care What Other People Think by Feynman The Cathedral & The Bazaar by Raymond Novels: The Soul of a New Machine by Kidder Where Wizards Stay up Late by Hafner