How to Convert Char Array to Int in C++ Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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:123456Convert Char Array to Int in C++To convert a char array to int in C++, we can use the atoi() 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 IntThe following program illustrates how we can convert a char array to int in C++ using the atoi function: C++ // C++ Program to Convert Char Array to Int #include <iostream> #include <cstdlib> using namespace std; int main() { char str[] = "12345"; int num = atoi(str); cout << "The integer value is: " << num << endl; return 0; } OutputThe integer value is: 12345 Time Complexity: O(N), where N is the length of the character array.Auxiliary Space: O(1) Comment More info S satwiksuman Follow Improve Article Tags : C++ Programs C++ cpp-data-types cpp-array CPP Examples misc-cpp +2 More Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++5 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++11 min readFile Handling through C++ Classes8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++4 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL3 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like