Home »
C++ programming »
C++ Reference »
C++ <cstdlib> header
atoll() Function with Example in C++
C++ atoll() function: Here, we are going to learn about the atoll() function with example of cstdlib header in C++ programming language.
Submitted by IncludeHelp, on May 26, 2020
C++ atoll() function
atoll() function is a library function of cstdlib header. It is used to convert the given string value to the integer value. It accepts a string containing an integer (integral) number and returns its long long long integer value.
Syntax of atoll() function:
C++11:
long long int atoll (const char * str);
Parameter(s):
- str – represents a string containing an integer (integral) number.
Return value:
The return type of this function is long long int, it returns the long long long integer converted value.
Example:
Input:
str = "123456789012345";
Function call:
atoll(str);
Output:
123456789012345
C++ code to demonstrate the example of atoll() function
// C++ code to demonstrate the example of
// atoll() function
#include <iostream>
#include <cstdlib>
#include <string.h>
using namespace std;
// main() section
int main()
{
char str[50];
strcpy(str, "123456789");
cout << "atoll(\"" << str << "\"): " << atoll(str) << endl;
strcpy(str, "-123456789");
cout << "atoll(\"" << str << "\"): " << atoll(str) << endl;
strcpy(str, "0");
cout << "atoll(\"" << str << "\"): " << atoll(str) << endl;
strcpy(str, "9876543120");
cout << "atoll(\"" << str << "\"): " << atoll(str) << endl;
strcpy(str, "-9876543120");
cout << "atoll(\"" << str << "\"): " << atoll(str) << endl;
strcpy(str, "123456789012345");
cout << "atoll(\"" << str << "\"): " << atoll(str) << endl;
return 0;
}
Output
atoll("123456789"): 123456789
atoll("-123456789"): -123456789
atoll("0"): 0
atoll("9876543120"): 9876543120
atoll("-9876543120"): -9876543120
atoll("123456789012345"): 123456789012345
Reference: C++ atoll() function