can u explain how in the converttoint function, in the line
ans+=(str[i]-‘0’]*p, how we are subtracting characters, why ‘0’ is used and how we are multiplying character with p which is an int.
Convert from string to int in string challenge
@skaushik.46, the concept used is called as typecasting let me explain one by one
typecasting allows one datatype to be converted to a higher level datatype :-
All the data types of the variables are upgraded to the data type of the variable with largest data type.
bool -> char -> short int -> int ->
unsigned int -> long -> unsigned ->
long long -> float -> double -> long double
1.how in the converttoint function, in the line ans+=(str[i]-‘0’]*p, how we are subtracting characters,
ans+=(str[i]-‘0’) , since - operator is not defined for characters but is defined for integers so what happens is compiler see that it does’nt have definition for subtraction of char so it upgrades char to int, which will be there ascii value for eg if str[i] is ‘7’ then ascii value of 7 is 55 and ascii value of ‘0’ is 48
so ans+=(str[i]-‘0’)*p will become ans+=(55-48) * p which is ans+=7 * p
- why ‘0’ is used and how we are multiplying character with p which is an int.
since after typecasting we get an integer output through subtraction thus we can multiply with p which is also an integer
I highly suggest you to read more about typecasting
u can refer this :- https://www.geeksforgeeks.org/type-conversion-in-c/
or any article you are confortable with
In case of any doubt feel free to ask 
Mark your doubt as RESOLVED if you got the answer