why we subtract a char to ‘0’, & how it convert a char to digit by subtracting it.
int digit=a[n-1]-‘0’;
why we subtract a char to ‘0’, & how it convert a char to digit by subtracting it.
int digit=a[n-1]-‘0’;
Hello @rprahulpal03 this is because as a character or a string are stored according to theri ASCII value and ascii value of numbers start from 48 i.e 0 and 1 is 49
so if the string at that particular index is 1i.e 49 in ascii value so if we will subtract 0 from it then the result will be 49-48 =1.
that is why we subtract 0 from it.
if you still have any doubt you can ask here:
Happy Learning!!
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.