The reason it works is because a char is a number. The most common form is that a char stores the ASCII or UTF-8 value for the character, and '4' would be translated into that value (e.g. 52).
In general, you would expect that the numbers would be in order, i.e. 0123456789. So, if you subtract the character with the value for '0' (e.g. 48), you should get the difference in position.
In your example:
1 2
char a = '4'; // a = 52
int ia = a - '0'; // ia = 52 - 48 = 4