title: What happens when we subtract a char integer from another char integer?
body: <p>The following code is a way to convert String into an Integer using recursion. I understood the process but cannot figure out what is happening when we do this:</p>
  
  <p><code>str.charAt(0) - '0'</code></p>
  
  <p>We can easily convert it into an int or double using parseInt or parseDouble. Then why are we subtracting a char '0' from a String (which is a number)? How does this convert our character into an int or double?</p>
  
  <pre><code>// Java implementation of the approach to convert a String to an Integer using Recursion
  public class GFG { 
  
      // Recursive function to convert string to integer 
      static int stringToInt(String str) 
      { 
  
          // If the number represented as a string 
          // contains only a single digit 
          // then returns its value 
          if (str.length() == 1) 
              return (str.charAt(0) - '0'); 
  
          // Recursive call for the sub-string 
          // starting at the second character 
          double y = stringToInt(str.substring(1)); 
  
          // First digit of the number 
          double x = str.charAt(0) - '0'; 
  
          // First digit multiplied by the 
          // appropriate power of 10 and then 
          // add the recursive result 
          // For example, xy = ((x * 10) + y) 
          x = x * Math.pow(10, str.length() - 1) + y; 
          return (int)(x); 
      } 
  
      // Driver code 
      public static void main(String[] args) 
      { 
          String str = "1235"; 
          System.out.print(stringToInt(str)); 
      } 
  } 
  
  </code></pre>