This is for use with an array, it is being used in a program that counts each occurrence of a letter read in from a .txt file. The question is mostly about character arithmetic and what happens inside of an array. Starting from the static_casting:
1 2 3 4 5 6
int index;
ch = toupper(ch);
index = static_cast<int>(ch)-static_cast<int>('A')
I know that static_cast<>() will change the thing in parens to the type of thing in the <> brackets; I assume that the above arithmetic is a hack that allows us to deal with exclusively letters, but how so?
1 2
if (0<= index && index < 26)
list[index]++
So the above would indicate that the arithmetic gets us into the "letter" range, and then increments the corresponding index by one. Does that mean that the only thing stored in an array is an integer value?
I think I get it mostly, its just the broader concept of the arithmetic that I don't understand, mostly.