Chapter 1: A Tutorial Introduction
So this chapter intends to set us up for success, by giving a breezy introduction on how to get running and learning most of the language.
Compiler
It starts by assuming we have access to cc. It seems that the C Compiler used at the time, predates GCC, but now essentially uses that. We can verify this as such:
$ cc --version
cc (GCC) 15.2.1 20251112
To make it easy for myself, I have created a new repo for the exercises and will be making a folder for each exercise and add a main.c file in there. That way, it will be trivially simple to compile and execute the program in a one-liner:
$ gcc main.c -ansi -pedantic -o main.out && ./main.out
Having -pedantic enforces standards compliance and -ansi forces the specific version that is used in the book (which is equivalent to -std=c90 - which we know as C89).
Exercises
Exercise 1-2 writes about escape sequences and there’s definitely some of them I didn’t know about. There’s also a pretty interesting historic article about printf on wikipedia. The name apparantly comes from 1956 and Fortran and is literally asking to print on the attached printer.
So there’s definitely a lot of convenience added in later versions of C. Exercise 1-5 highlights that inline declarations for loops aren’t allowed:
error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
In Chapter 1.5.2, the book talks about using double for counters, due to int being 16 bit at the time, being limited to 32768 and thus subject to overflows rather quickly. This isn’t the case these days with 32 bit being the default in most systems. This is why some C programs these days start out with defines, that has asserts to check the size of basic types.
Exercises 1-8, 1-9 and 1-10 feels like the brain teaser that some of the easier leetcode questions might be. Those were fun!
Exercise 1-13 and 1-14 utilizes arrays, and here I got to look at zero initialization of arrays, as a thing. The book example declares it, and then loops over the array and sets the values to 0. I think I’d just do like this:
int foo[256] = {0};
The rest of the chapter introduces functions, arguments, char[], scopes/extern and declares that this is the “core” of C, allowing to built most things from this simple core set. That’s a bold claim. Let’s see where this takes me in the next chapters.
As I have some experience in programming, I will be skipping the rest of the introduction exercises for chapter 1 to move on.