title: atoi implementation in C++
body: <p>Given <a href="http://www.geeksforgeeks.org/write-your-own-atoi/" rel="nofollow">this implementation</a> of atoi in C++ </p>
  
  <pre><code>// A simple atoi() function
  int myAtoi(char *str)
  {
      int res = 0; // Initialize result
  
      // Iterate through all characters of input string and update result
      for (int i = 0; str[i] != '\0'; ++i)
          res = res*10 + str[i] - '0';
  
      // return result.
      return res;
  }
  
  // Driver program to test above function
  int main()
  {
      char str[] = "89789";
      int val = myAtoi(str);
      printf ("%d ", val);
      return 0;
  }
  </code></pre>
  
  <p>How exactly does the line </p>
  
  <pre><code>res = res*10 + str[i] - '0';
  </code></pre>
  
  <p>Change a string of digits into int values? (I'm fairly rusty with C++ to be honest. )</p>