How to Convert Char Array to Int in C++ Last Updated : 28 May, 2024 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 infoAdvertise with us Next Article How to Convert Char Array to Int in C++ S satwiksuman Follow Improve Article Tags : C++ Programs C++ cpp-data-types cpp-array CPP Examples misc-cpp +2 More Practice Tags : CPP Similar Reads Convert String to Char Array in C++ In C++, we usually represent text data using the std::string object. But in some cases, we may need to convert a std::string to a character array, the traditional C-style strings. In this article, we will learn how to convert the string to char array in C++.ExamplesInput: str = "geeksforgeeks"Output 4 min read How to Convert a std::string to char* in C++? In C++, strings are the textual data that is represented in two ways: std::string which is an object, and char* is a pointer to a character. In this article, we will learn how to convert a std::string to char* in C++. Example Input:string myString = "GeeksforGeeks";Output:char * myString = "Geeksfor 1 min read How to Convert ASCII Value into char in C++? In C++, ASCII (American Standard Code for Information Interchange) values are numerical representations of characters that are used in the C++. In this article, we will learn how to convert an ASCII value to a char in C++. Example: Input: int asciiValue = 65; Output: Character for ASCII value 65 is: 2 min read How to Convert Hex String to Byte Array in C++? A Hex String is a combination of the digits 0-9 and characters A-F and a byte array is an array used to store byte data types only. The default value of each element of the byte array is 0. In this article, we will learn how to convert a hex string to a byte array. Example: Input: Hex String : "2f4a 2 min read How to Convert a Single Character to String in C++? A string is a generally made up of a sequence of multiple characters. In this article, we will learn how to convert a single character to a string in C++.Example:Input: c = 'A'Output: s = "a"Explanation: Character c is converted to a string.Input: c = '#'Output: s = "#"Explanation: Character c is co 4 min read Convert character array to string in C++ This article shows how to convert a character array to a string in C++. The std::string in c++ has a lot of inbuilt functions which makes implementation much easier than handling a character array. Hence, it would often be easier to work if we convert a character array to string. Examples: Input: ch 4 min read How to Convert Float to int in C++? In C++, the float is a short term for floating point value that is used to define numeric values with decimal points. The floating point numbers can be converted to integers using the process called type casting. In this article, we will learn how to convert a float value to an int in C++. Example: 2 min read How to Convert wstring to int in C++? In C++, std::wstring is a type of string where each character is of a wide character type. These types of strings can be used to store the numerical strings which can then be converted to their corresponding type. In this article, we will see how to convert a wstring to an int in C++. Input: wstr = 2 min read How to Initialize Vector of Char Arrays in C++? In C++, a vector is a dynamic array that can grow and shrink in size. A char array is a sequence of characters, typically used to represent strings. In this article, we will learn how to initialize a vector of char arrays in C++. Example: myVector: {âappleâ, âbananaâ, âcherryâ}Initializing a Vector 2 min read How to Compare Two Substrings in a Character Array in C++? In C++, character arrays are used to store a sequence of characters also known as strings. A Substring is a continuous sequence of characters within a string. In this article, we will learn how we can compare two substrings in a character array in C++. Examples: Input: string: "Hello World" Substrin 2 min read Like