Last updated on 2025/08/02
Pages 9-34
Check The C Programming Language Chapter 1 Summary
The only way to learn a new programming language is by writing programs in it.
This is a big hurdle; to leap over it you have to be able to create the program text somewhere, compile it successfully, load it, run it, and find out where your output went.
We want to get you as quickly as possible to the point where you can write useful programs.
Experienced programmers should be able to extrapolate from the material in this chapter to their own programming needs.
The statements of a function are enclosed in braces { }.
In any case, we are not trying to be complete or even precise.
There are plenty of different ways to write a program for a particular task.
The C programming language is a powerful tool for creating a wide variety of applications.
Appropriate commenting can make a program easier to understand.
A function provides a convenient way to encapsulate some computation, which can then be used without worrying about its implementation.
Pages 35-51
Check The C Programming Language Chapter 2 Summary
Variables and constants are the basic data objects manipulated in a program.
The type of an object determines the set of values it can have and what operations can be performed on it.
It's wise to choose variable names that are related to the purpose of the variable.
A constant expression is an expression that involves only constants.
Each compiler is free to choose appropriate sizes for its own hardware.
The qualifier const can be applied to the declaration of any variable to specify that its value will not be changed.
The conditional expression often leads to succinct code.
A character is converted to an integer, either by sign extension or not.
The moral is that writing code that depends on order of evaluation is a bad programming practice in any language.
This representation means that there is no limit to how long a string can be, but programs must scan a string completely to determine its length.
Pages 52-61
Check The C Programming Language Chapter 3 Summary
The control-flow of a language specifies the order in which computations are performed.
The if-else statement is used to express decisions.
The else part is optional.
Sometimes this is natural and clear; at other times it can be cryptic.
If that isn't what you want, braces must be used to force the proper association.
The ambiguity is especially pernicious in situations like this.
The last else part handles the 'none of the above' or default case.
The advantages of keeping loop control centralized are even more obvious when there are several nested loops.
The break statement provides an early exit from for, while, and do.
Code that relies on goto statements is generally harder to understand and to maintain than code without gotos.
Pages 62-82
Check The C Programming Language Chapter 4 Summary
Functions break large computing tasks into smaller ones, and enable people to build on what others have done instead of starting over from scratch.
Appropriate functions hide details of operation from parts of the program that don't need to know about them, thus clarifying the whole, and easing the pain of making changes.
C has been designed to make functions efficient and easy to use.
A program may reside in one or more source files. Source files may be compiled separately and loaded together.
Three small pieces are better to deal with than one big one, because irrelevant details can be buried in the functions.
When we later need more sophisticated pattern matching, we only have to replace strindex; the rest of the code can remain the same.
Communication between the functions is by arguments and values returned by the functions, and through external variables.
Control also returns to the caller with no value when execution 'falls off the end' of the function by reaching the closing right brace.
A declaration announces the properties of a variable; a definition also causes storage to be set aside.
Recursion is especially convenient for recursively defined data structures.
Pages 83-113
Check The C Programming Language Chapter 5 Summary
A pointer is a variable that contains the address of a variable.
Pointers are sometimes the only way to express a computation, and partly because they usually lead to more compact and efficient code.
With discipline, however, pointers can also be used to achieve clarity and simplicity.
Pointers and arrays are closely related; this chapter also explores this relationship and shows how to exploit it.
The main change in ANSI C is to make explicit the rules about how pointers can be manipulated.
If ip points to the integer x, then *ip can occur in any context where x could.
A pointer is constrained to point to a particular kind of object.
Pointers are variables themselves; they can be stored in arrays just as other variables.
C is consistent and regular in its approach to address arithmetic; its integration of pointers, arrays, and address arithmetic is one of the strengths of the language.
Since pointers are variables, they can be used without dereferencing.
Pages 114-134
Check The C Programming Language Chapter 6 Summary
A structure is a collection of one or more variables, possibly of different types, grouped together under a single name for convenient handling.
Structures help to organize complicated data, particularly in large programs, because they permit a group of related variables to be treated as a unit instead of as separate entities.
A structure declaration defines a type.
A structure can be initialized by following its definition with a list of initializers.
Each statement declares x, y and z to be variables of the named type and causes space to be set aside for them.
Structures may not be compared.
Let us investigate structures by writing some functions to manipulate points and rectangles.
The structure member operator ``.'' connects the structure name and the member name.
If a large structure is to be passed to a function, it is generally more efficient to pass a pointer than to copy the whole structure.
A typedef declaration does not create a new type in any sense; it merely adds a new name for some existing type.
Pages 135-150
Check The C Programming Language Chapter 7 Summary
Programs interact with their environment in much more complicated ways than those we have shown before.
The ANSI standard defines these library functions precisely, so that they can exist in compatible form on any system where C exists.
Programs that confine their system interactions to facilities provided by the standard library can be moved from one system to another without change.
Regardless of how the functions are implemented on a given machine, programs that use them are shielded from knowledge of the character set.
The output function printf translates internal values to characters.
The format string contains two types of objects: ordinary characters, which are copied to the output stream, and conversion specifications, each of which causes conversion and printing of the next successive argument to printf.
It is easy to implement our getline from fgets.
One program that illustrates the need for such operations is cat, which concatenates a set of named files into the standard output.
For no obvious reason, the standard specifies different return values for ferror and fputs.
A typical but incorrect piece of code is this loop that frees items from a list: for (p = head; p != NULL; p = p->next) /* WRONG */ free(p);
Pages 151-235
Check The C Programming Language Chapter 8 Summary
If you use UNIX, this should be directly helpful, for it is sometimes necessary to employ system calls for maximum efficiency, or to access some facility that is not in the library.
Since the ANSI C library is in many cases modeled on UNIX facilities, this code may help your understanding of the library as well.
In the UNIX operating system, all input and output is done by reading or writing files, because all peripheral devices, even keyboard and screen, are files in the file system.
Putting these facts together, we can write a simple program to copy its input to its output ... this program will copy anything to anything, since the input and output can be redirected to any file or device.
Whenever input or output is to be done on the file, the file descriptor is used instead of the name to identify the file.
The system checks your right to do so (Does the file exist? Do you have permission to access it?) and if all is well, returns to the program a small non-negative integer called a file descriptor.
The file pointer used by the standard library, or to the file handle of MS-DOS, is analogous to the file descriptor.
Whenever you define something in programming, it is essential to not only understand how to use it but also the why behind it.
The first assumption is that we must understand how important it is to maintain the integrity of the structures we create.
A program that intends to process many files must be prepared to re-use file descriptors.