Chapter 2: Types, Operators and Expressions
Exercises from “The C Programming Language” (2nd Edition) by Brian W. Kernighan and Dennis M. Ritchie.
Exercises
| # | Description | Source |
|---|---|---|
| 2-01 | Determine ranges of char, short, int, long | - |
| 2-02 | Write equivalent of for without && or || |
- |
| 2-03 | Write htoi(s): hex string to integer |
- |
| 2-04 | squeeze(s1, s2): delete chars in s1 that match any in s2 |
- |
| 2-05 | any(s1, s2): return first position of any char of s2 in s1 |
- |
| 2-06 | setbits(x, p, n, y): set n bits at position p |
- |
| 2-07 | invert(x, p, n): invert n bits at position p |
- |
| 2-08 | rightrot(x, n): rotate x right by n bits |
- |
| 2-09 | Faster bit counting using x &= (x-1) |
- |
| 2-10 | Rewrite lower using conditional expression |
- |
Compilation
gcc -Wall -Wextra -o exercise exercise.c
./exercise