We recommend using Visual Studio 2017

strtoll, _strtoll_l, wcstoll, _wcstoll_l


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at strtoll, _strtoll_l, wcstoll, _wcstoll_l.

Converts a string to a long long value.

long long strtoll(  
   const char *nptr,  
   char **endptr,  
   int base   
long long wcstoll(  
   const wchar_t *nptr,  
   wchar_t **endptr,  
   int base   
long long _strtoll_l(  
   const char *nptr,  
   char **endptr,  
   int base,  
   _locale_t locale  
long long _wcstoll_l(  
   const wchar_t *nptr,  
   wchar_t **endptr,  
   int base,  
   _locale_t locale  


Null-terminated string to convert.

Pointer to the character that stops the scan.

Number base to use.

The locale to use.

strtoll returns the value that's represented in the string nptr, except when the representation would cause an overflow—in that case, it returns LLONG_MAX or LLONG_MIN. The function returns 0 if no conversion can be performed. wcstoll returns values analogously to strtoll.

LLONG_MAX and LLONG_MIN are defined in LIMITS.H.

If nptr is NULL or the base is nonzero and either less than 2 or greater than 36, errno is set to EINVAL.

For more information about return codes, see errno, _doserrno, _sys_errlist, and _sys_nerr.

The strtoll function converts nptr to a long long. Both functions stop reading the string nptr at the first character they cannot recognize as part of a number. This may be the terminating null character, or it may be the first numeric character that's greater than or equal to base. wcstoll is a wide-character version of strtoll; its nptr argument is a wide-character string. Otherwise, these functions behave identically.

Generic-Text Routine Mappings

TCHAR.H routine_UNICODE & _MBCS not defined_MBCS defined_UNICODE defined

The locale's LC_NUMERIC category setting determines recognition of the radix character in nptr; for more information, see setlocale, _wsetlocale. The functions that don't have the _l suffix use the current locale; _strtoll_l and _wcstoll_l are identical to the corresponding functions that don't have the suffix, except that they instead use the locale that's passed in. For more information, see Locale.

If endptr is not NULL, a pointer to the character that stopped the scan is stored at the location that's pointed to by endptr. If no conversion can be performed (no valid digits were found or an invalid base was specified), the value of nptr is stored at the location that's pointed to by endptr.

strtoll expects nptr to point to a string of the following form:

[whitespace] [{+ | }] [0 [{ x | X }]] [digits | letters]

A whitespace may consist of space and tab characters, which are ignored; digits are one or more decimal digits; letters are one or more of the letters 'a' through 'z' (or 'A' through 'Z'). The first character that does not fit this form stops the scan. If base is between 2 and 36, then it is used as the base of the number. If base is 0, the initial characters of the string that's pointed to by nptr are used to determine the base. If the first character is '0' and the second character is not 'x' or 'X', the string is interpreted as an octal integer. If the first character is '0' and the second character is 'x' or 'X', the string is interpreted as a hexadecimal integer. If the first character is '1' through '9', the string is interpreted as a decimal integer. The letters 'a' through 'z' (or 'A' through 'Z') are assigned the values 10 through 35; only letters whose assigned values are less than base are permitted. The first character outside the range of the base stops the scan. For example, if base is 0 and the first character scanned is '0', an octal integer is assumed and an '8' or '9' character stops the scan.

RoutineRequired header
strtoll, _strtoll_l<stdlib.h>
wcstoll, _wcstoll_l<stdlib.h> or <wchar.h>

For additional compatibility information, see Compatibility.

Data Conversion
setlocale, _wsetlocale
String to Numeric Value Functions
strtod, _strtod_l, wcstod, _wcstod_l
strtol, wcstol, _strtol_l, _wcstol_l
strtoul, _strtoul_l, wcstoul, _wcstoul_l
atof, _atof_l, _wtof, _wtof_l