what s[i]-'0' does

s[i]-'0' is an expression in C++. Here's an explanation for each step:

  1. s[i]: Accesses the character at index i in the array or string s.

  2. '0': Represents the character literal '0'. In ASCII encoding, the character '0' has a numerical value of 48.

  3. s[i]-'0': Converts the character at index i in string s to its corresponding integer value. This is done by subtracting the ASCII value of '0' from the ASCII value of the character at index i.

In summary, the expression s[i]-'0' is used to convert a character digit (e.g., '0', '1', ..., '9') to its equivalent integer value.