ans+= (s[i]-'0')*p;
why are we subtracting 0 every time ? and how is char type multiplied with a char type?
ans+= (s[i]-'0')*p;
why are we subtracting 0 every time ? and how is char type multiplied with a char type?
When you performing arithmetic operation, they are actually being converted to their ascii value equivalent and then the arithmetic operation is performed.
So actually your statement is equivalent to
ans+=(asci value of s[i]-ascii value of ‘0’) * p
So s[i]-‘0’ will actually give the number/digit in integer form.