Search code examples
cstringatoi

Not able to understand Atoi function - *string - '0'


What exactly does the below statement do?

const char *string
*string - '0'

Thanks!


Solution

  • It subtracts the value of the character '0' from the character pointed to by string, turning it into a numerical value. So for example the character '9' will be turned into the integer 9.