What is the use of the following statement in the solution?

(s[j] - ‘0’) this part in stoint

hello @vipulch

it convert integer character to number .
i.e it converts charcter like ‘8’ to 8.

note ‘8’ is charcter , 8 is integr.

so if u subtract ‘0’ from any such numeric charcter then u will get number.

in the video we doing the same thing

that means char-char gives integer?

or is it because we are putting the value in an integer?

char is nothing but number only , compiler use characters ascii values for any arithmetic operation.

for example if u write ‘8’ then compiler use its ascii number which is 56.
similarly ‘0’ is equivalent to number 48.

so when u subtract ‘8’-‘0’ then its ascii value is used .
i.e ‘8’-‘0’ is 56-48 which is 8

1 Like

now i got it, thanks!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.