VOOZH about

URL: https://www.geeksforgeeks.org/cpp/how-to-convert-char-array-to-int-in-cpp/

⇱ How to Convert Char Array to Int in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Convert Char Array to Int in C++

Last Updated : 23 Jul, 2025

In C++, a character array is treated as a sequence of characters also known as a string. Converting a character array into an integer is a common task that can be performed using various methods and in this article, we will learn how to convert char array to int in C++.

Example

Input:
char arr1[] ="123456"

Output:
123456

Convert Char Array to Int in C++

To convert a char array to int in C++, we can use the function provided by the <cstdlib> header. Following is the syntax to use atoi function:

Syntax of atoi()

int atoi(const char arr)

where:

  • arr: is the name of the character array.
  • return type: Integer equivalent to the character array or 0 if the input was not valid.

C++ Program to Convert Char Array to Int

The following program illustrates how we can convert a char array to int in C++ using the atoi function:


Output
The integer value is: 12345

Time Complexity: O(N), where N is the length of the character array.
Auxiliary Space: O(1)

Comment