K & R C Exercise Solutions.

We have already provided solutions to all the exercises in the book “C Programming Language (2nd Edition)“ popularly known as K & R C book. In this blog post I will give links to all the chapters of the “C Programming Language (2nd Edition)” popularly known as K & R C book for easy reference. Chapter …

K&R C Chapter 5 Exercise Solutions — Pointers and Arrays

Chapter 5: Pointers and Arrays is the chapter C beginners fear most — and with reason. K&R covers pointer arithmetic, the equivalence between pointers and arrays, pointers to functions, and multi-dimensional arrays. The exercises build real utilities: getfloat, strncpy/strncat/strncmp from scratch, a tail command, a sort program with -r/-n/-f/-d flags, and a full C declaration …

K&R C Chapter 4 Exercise Solutions — Functions and Program Structure

Chapter 4: Functions and Program Structure is where K&R builds a non-trivial program: a reverse Polish notation (RPN) calculator. The exercises extend it — adding modulo, unary minus, variables, and last-printed-value recall. Other exercises cover recursive printd, recursive itoa, and the C preprocessor. Exercise 4-12 (recursive itoa) and 4-13 (recursive reverse) are elegance tests. These …

K&R C Chapter 2 Exercise Solutions — Types, Operators, and Expressions

Chapter 2: Types, Operators, and Expressions covers C’s type system and operators in depth. The exercises focus on bitwise manipulation — rotating bits, setting and clearing fields, counting set bits — and type-conversion edge cases. Exercise 2-9 (x &= (x-1) deletes the rightmost 1-bit) is a classic bit-manipulation trick worth memorising. These are worked solutions …

K&R C Chapter 1 Exercise Solutions — A Tutorial Introduction

Chapter 1: A Tutorial Introduction is where K&R C begins — and it moves faster than most C books. By exercise 1-8 you are counting characters by category; by 1-13 you are drawing histograms; by 1-22 you are folding long lines. The chapter uses only a tiny subset of C deliberately: loops, if/else, basic functions, …