![]() |
VOOZH | about |
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
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:
int atoi(const char arr)where:
The following program illustrates how we can convert a char array to int in C++ using the atoi function:
The integer value is: 12345
Time Complexity: O(N), where N is the length of the character array.
Auxiliary Space: O(1)