what s[i]-'0' does
s[i]-'0'
is an expression in C++. Here's an explanation for each step:
s[i]
: Accesses the character at indexi
in the array or strings
.'0'
: Represents the character literal '0'. In ASCII encoding, the character '0' has a numerical value of 48.s[i]-'0'
: Converts the character at indexi
in strings
to its corresponding integer value. This is done by subtracting the ASCII value of '0' from the ASCII value of the character at indexi
.
In summary, the expression s[i]-'0'
is used to convert a character digit (e.g., '0', '1', ..., '9') to its equivalent integer value.