VOOZH about

URL: https://www.geeksforgeeks.org/c/c-program-for-char-to-int-conversion/

⇱ C Program For Char to Int Conversion - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C Program For Char to Int Conversion

Last Updated : 23 Jul, 2025

Write a C program to convert the given numeric character to integer.

Example:

Input: '3'
Output: 3
Explanation: The character '3' is converted to the integer 3.

Input: '9'
Output: 9
Explanation: The character '9' is converted to the integer 9.

Different Methods to Convert the char to int in C

There are 3 main methods to convert the char to int in C language as follows:

Let's discuss each of these methods in detail.

1. Using ASCII Values

Each character in C has an ASCII value, a unique numerical representation. For numeric characters like '0', '1', etc., the ASCII value starts from 48 for '0' and increases sequentially. To convert a char to its integer equivalent, subtract the ASCII value of '0' from the character.

C Program to Convert char to int Using ASCII Values


Output
The integer value of character '7' is 7

Time Complexity: O(1)
Space Complexity: O(1)

2. Using sscanf() Function

The sscanf() function can be used to read formatted input from a string. It can convert a character to an integer by treating the character as a string and reading it using the format specifier for an integer (%d).

C Program to Convert char to int Using sscanf() Function


Output
103

Time Complexity: O(1)
Space Complexity: O(1)

3. Using atoi() Function

The atoi() function from the C Standard Library <stdlib.h> can convert a string of digits into an integer. Although atoi() is designed for strings, it can be used with single-character strings.

C Program to Convert char to int Using atoi()


Output
The integer value of character '5' is 5

Time Complexity: O(1)
Space Complexity: O(1)

Comment