char to int in c

Converting a char to an int in C

To convert a char to an int in C, you can simply subtract the ASCII value of '0' from the char. Here are the steps:

  1. Get the ASCII value of '0': The ASCII value of '0' is 48.
  2. Subtract the ASCII value of '0' from the char: This will give you the integer value of the char.

For example, if you have the char '5', you can convert it to the integer 5 by subtracting the ASCII value of '0' (48) from the ASCII value of '5' (53), resulting in 5.

[[SOURCE 10]]