The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie — universally known as K&R C — is the definitive reference for the C language. First published in 1978, the ANSI C second edition (1988) remains the gold standard for learning C correctly: terse, precise, and written by the language’s own creators.
This page is a complete index of worked solutions to all exercises across all 7 chapters of the 2nd edition. Each solution is written in standard ANSI C, compiles cleanly with gcc, and includes the exercise statement for context.
Get the book: The C Programming Language, 2nd Edition — Brian W. Kernighan & Dennis M. Ritchie (Amazon.in)
Exercise Solutions by Chapter
| Chapter | Topic | Exercises | Key Concepts |
|---|---|---|---|
| Chapter 1 | A Tutorial Introduction | 26 | Hello World, loops, functions, character I/O, word counting |
| Chapter 2 | Types, Operators, and Expressions | 10 | Data types, bitwise operators, ternary expressions, type conversions |
| Chapter 3 | Control Flow | 6 | if-else, switch, loops, break/continue, binary search |
| Chapter 4 | Functions and Program Structure | 14 | Recursion, scope, header files, static variables, reverse Polish calculator |
| Chapter 5 | Pointers and Arrays | 20 | Pointer arithmetic, array/pointer equivalence, command-line arguments, sorting |
| Chapter 6 | Structures | 6 | struct, linked lists, hash tables, self-referential structures, typedef |
| Chapter 7 | Input and Output | 9 | printf/scanf format strings, file I/O, error handling, line I/O |
Total: 91 exercises covering all topics in the 2nd edition. Chapter 8 (The UNIX System Interface) is system-specific and not included.
Individual Exercise Index
Chapter 1 — A Tutorial Introduction
- Exercise 1-1a
- Exercise 1-1b
- Exercise 1-1c
- Exercise 1-2
- Exercise 1-3
- Exercise 1-4
- Exercise 1-5
- Exercise 1-6
- Exercise 1-7
- Exercise 1-8
- Exercise 1-9
- Exercise 1-10
- Exercise 1-11
- Exercise 1-12
- Exercise 1-13
- Exercise 1-14
- Exercise 1-15
- Exercise 1-16
- Exercise 1-17
- Exercise 1-18
- Exercise 1-19
- Exercise 1-20
- Exercise 1-21
- Exercise 1-22
- Exercise 1-23
- Exercise 1-24
Chapter 2 — Types, Operators, and Expressions
- Exercise 2-1
- Exercise 2-2
- Exercise 2-3
- Exercise 2-4
- Exercise 2-5
- Exercise 2-6
- Exercise 2-7
- Exercise 2-8
- Exercise 2-9
- Exercise 2-10
Chapter 3 — Control Flow
Chapter 4 — Functions and Program Structure
- Exercise 4-1
- Exercise 4-2
- Exercise 4-3
- Exercise 4-4
- Exercise 4-5
- Exercise 4-6
- Exercise 4-7
- Exercise 4-8
- Exercise 4-9
- Exercise 4-10
- Exercise 4-11
- Exercise 4-12
- Exercise 4-13
- Exercise 4-14
Chapter 5 — Pointers and Arrays
- Exercise 5-1
- Exercise 5-2
- Exercise 5-3
- Exercise 5-4
- Exercise 5-5
- Exercise 5-6
- Exercise 5-7
- Exercise 5-8
- Exercise 5-9
- Exercise 5-10
- Exercise 5-11
- Exercise 5-12
- Exercise 5-13
- Exercise 5-14
- Exercise 5-15
- Exercise 5-16
- Exercise 5-17
- Exercise 5-18
- Exercise 5-19
- Exercise 5-20
Chapter 6 — Structures
Chapter 7 — Input and Output
- Exercise 7-1
- Exercise 7-2
- Exercise 7-3
- Exercise 7-4
- Exercise 7-5
- Exercise 7-6
- Exercise 7-7
- Exercise 7-8
- Exercise 7-9
About The C Programming Language
The C Programming Language (2nd edition, 1988) by Brian Kernighan and Dennis Ritchie is the book that defined how C is taught and written. Ritchie created C at Bell Labs in 1972; Kernighan co-developed it and wrote the majority of the book. It is compact (272 pages), precise, and still the most reliable reference for ANSI C.
If you are learning C seriously, working through the exercises is essential. The exercises build on each other — by Chapter 5 you are implementing sorting algorithms and string functions from scratch using only pointers and arrays. These solutions are meant to be studied, not copied: understanding why each solution works is the goal.
See also: Complete C Programs List | C Aptitude Questions