sir, please tell me how digit=a[n-1]-‘0’; gives the last digit ?
String to integer recusrion video
hi @Abhishmu5 suppose the string is “1234”
s[n-1] gives '4' which is a character with ascii value 52. '0' is a character with ascii value 48.
So '4' - '0' will give us the difference between their ascii values, ie 52 - 48 = 4. Hence we will get the last digit.
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.