pure math
shuiming: ndigit['4'-'0'], how this work, logic? interesting, c is an int, '0' is 48 in machine code, '4' is 52. that clear the cloud.
cc: Exactly — one small terminology polish: it's the character encoding (ASCII specifically), not "machine code." Machine code is the CPU's actual instructions (add, jump, load, etc.); ASCII is just the lookup table mapping symbols like '0' and '4' to integers, which then get stored and manipulated as ordinary numbers. But the core insight is exactly right — c is always just an int, '0' and '4' are just two particular int values (48 and 52), and everything downstream (c - '0', array indexing) is plain integer arithmetic with no special "character" behavior involved at all.
shuiming: pure math
cc: Exactly — that's the whole reveal K&R is walking you toward with this exercise. There's no "character type" doing anything special in C; char is just a small integer with a naming convention. '4' - '0' isn't string manipulation or type conversion magic, it's subtraction, the same operation as 52 - 48. Every text-processing trick you've used today — state == IN, c - '0', even getchar() != EOF — is arithmetic and comparison on plain integers wearing a "this represents a character" costume. Once that clicks, C stops looking like it has special rules for text and starts looking like what it actually is: bytes and math, all the way down.