Memory only holds numbers. So every character is stored as a number — its code — and a string is a row of those numbers sitting next to each other in memory. Which number each character gets, and how many bytes it takes, is decided by an encoding.
The oldest encoding still in daily use, ASCII, gives 128 characters the numbers 0 to 127 — enough for English letters, digits, punctuation and a few control characters. Each one fits in a single byte. The ranges are worth remembering:
'0'–'9' are 48–57.'A'–'Z' are 65–90.'a'–'z' are 97–122 — exactly 32 more than the uppercase letter.Members only · free account
The rest of this lesson, with 5 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson