Luke Sheppard's blog about information security, web development, and hacking 

Home Blog Reading about C pointers and such

Reading about C pointers and such

Woman sitting at Univac console at the  Lawrence Livermore National Laboratory.

Univac computer console and IBM equipment, October 1956. Lawrence Livermore accepted delivery of its first computer—a Univac—in 1952, the year of the Laboratory’s founding. Courtesy of Lawrence Livermore National Laboratory.

Pointers in the C language have tortured a few generations of programmers by now. But they are also one of the most useful, powerful, and important parts of the language. I’ve read the “Pointers and Arrays” chapter in the Kernighan and Ritchie book, The C Programming Language, probably a dozen times over the years. The first couple times through were baffling.

Book cover for the K and R C book

The venerable and timeless K and R C book.

 

Eventually, I took a class in C at the university where I work, and that helped a lot. Then, a couple years later, I discovered the 1953 and 1959  versions of the Univac programming manual. Wow! The 1953 version has an astoundingly detailed walkthrough of how to move individual bits around within a limited amount of memory registers with a very limited set of logical operators. The 1959 version has similar content, but a little more user friendly, and it has very helpful illustrations.

 

Page 24 of the Univac 1 Programming Manual, 1959

Page 24 of the Univac 1 Programming Manual, 1959. This is an illustration of using various addition operators to copy a value to multiple memory registers. From chapter 2, Introduction to Coding.

None of it is done with pointers of course, but the view into rigorously economical use of registers and logic is very revealing. For me, I found it to really be an important step in understanding how things like C pointers work. That is to say, I’m still working on fully understanding what pointers can do in C.

Then I bought this book for 50¢ at my local library: Understanding Pointers in C by Yashwant Kanetkar, 2nd edition.

Picture of the cover of Pointers in C, by Yashwant Kanetkar, 2nd edition

Pointers in C, by Yashwant Kanetkar, 2nd edition

 

They sell some of the books people donate to them. This one was printed in India. So it has some unexpected English language quirks, adding to the enjoyment. The examples and explanations are clearly written and really reveal the author’s enthusiasm. It is a welcome contrast to the strict concision of the K & R book.

This book is now in its 4th edition.
 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn