The C atoll() function converts decimal text to long long. Leading white space and an optional sign are accepted. The function consumes a decimal prefix but offers no end pointer.
This function is declared in <stdlib.h>. Its contract matters as much as its call: validate every required precondition, check any documented sentinel, and keep ownership or host effects clear in the surrounding code. A valid in-range prefix produces its long long value. Invalid or out-of-range input cannot be diagnosed reliably; use strtoll(). The examples below move from the direct call to an edge condition and a practical use.
Syntax
Start with this concrete atoll() call:
C
atoll("9000000000");
Call
What it does
atoll("9000000000");
Converts decimal text to long long using the concrete values shown.
Include <stdlib.h>. Also include headers that declare any types, limits, locale tools, or I/O functions used around the call.
Library declaration
C
long long atoll(const char *str);
Parameters
Parameter
Description
str
Null-terminated byte string containing a decimal integer.
Return Value
Return Value
Description
long long value
The converted decimal value.
0LL
Either a valid zero or an unreported conversion problem.
C Examples
Example 1 — Convert known text
This complete program demonstrates a distinct part of the atoll() contract and checks the result or precondition that matters for the scenario.
C
#include <stdio.h>
#include <stdlib.h>
int main(void) {
const char *text = "42";
long long value = atoll(text);
printf("%lld\n", value);
return 0;
}
Output
42
How It Works
Step 1. Store the known input as a C string.
Step 2. Pass it to atoll().
Step 3. The function accepts the numeric spelling.
Step 4. Print the long long result; validated input should use strtol instead.
Example 2 — Accept a leading sign
This complete program demonstrates a distinct part of the atoll() contract and checks the result or precondition that matters for the scenario.
C
#include <stdio.h>
#include <stdlib.h>
int main(void) {
const char *text = "-17";
long long value = atoll(text);
printf("%lld\n", value);
return 0;
}
Output
-17
How It Works
Step 1. Store the known input as a C string.
Step 2. Pass it to atoll().
Step 3. The function accepts the numeric spelling.
Step 4. Print the long long result; validated input should use strtol instead.
Example 3 — Observe prefix conversion
This complete program demonstrates a distinct part of the atoll() contract and checks the result or precondition that matters for the scenario.
C
#include <stdio.h>
#include <stdlib.h>
int main(void) {
const char *text = "120items";
long long value = atoll(text);
printf("%lld\n", value);
return 0;
}
Output
120
How It Works
Step 1. Store the mixed input as a C string.
Step 2. Pass it to atoll().
Step 3. The function stops after the numeric prefix.
Step 4. Print the long long result; validated input should use strtol instead.
Frequently Asked Questions
atoll() converts decimal text to long long. Leading white space and an optional sign are accepted. The function consumes a decimal prefix but offers no end pointer.
Include <stdlib.h> before calling atoll().
A valid in-range prefix produces its long long value. Invalid or out-of-range input cannot be diagnosed reliably; use strtoll().
atoll() does not provide robust validation or overflow reporting. Prefer strtoll() with endptr and errno for external input.
The function is specified by the C standard library. Exact limits, locale behavior, environment behavior, allocation capacity, or host effects can still vary where relevant.