Skip to content

Characters are numbers too

Read · 1 of 4

Every char has a number

Behind the scenes 'a' is 97, 'b' is 98, and so on. So 'a' + 2 is 'c', and letters can be compared like numbers.

Digits are in order too, so c - '0' turns the character '7' into the number 7. toupper(c) and tolower(c) (from #include <cctype>) change case.