Why we use str[i] - '0' in ConvertToInt( ) function inside for loop?

In String 05 - Solving a String Challenge, sir has made a function convertToInt() to convert the string into an integer value for numeric comparison. There he created a for loop for iteration over each element of string str but I didn’t understood why he did (str[i] - ‘0’) what is the use of this and why we need to subtract ‘0’ because even if zero is there in the beginning or in the end our answer will not change

hi @gitansh1
we are doing str[i] - ‘0’ to extarct character from the ith position and convert it to integer…

Then what is the use of subtracting ‘0’ from str[i]

if we simply write int x = str[i], then it will Ascii value of that character…
but by doing int x = str[i] - ‘0’, we get the actual integer value of that character…

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.