isdigit - cppreference.com
Namespaces
Variants

isdigit

From cppreference.com
< c | string | byte
Defined in header <ctype.h>
int isdigit( int ch );

Checks if the given character is a numeric character (0123456789).

The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.

Parameters

ch - character to classify

Return value

Non-zero value if the character is a numeric character, zero otherwise.

Notes

isdigit and isxdigit are the only standard narrow character classification functions that are not affected by the currently installed C locale, although some implementations (e.g. Microsoft in 1252 codepage) may classify additional single-byte characters as digits.

Example

#include <ctype.h>
#include <limits.h>
#include <stdio.h>
 
int main(void)
{
    for (int ndx = 0; ndx <= UCHAR_MAX; ++ndx)
        if (isdigit(ndx))
            printf("%c", ndx);
    printf("\n");
}

Output:

0123456789

References

  • C23 standard (ISO/IEC 9899:2024):
  • 7.4.1.5 The isdigit function (p: TBD)
  • C17 standard (ISO/IEC 9899:2018):
  • 7.4.1.5 The isdigit function (p: 146)
  • C11 standard (ISO/IEC 9899:2011):
  • 7.4.1.5 The isdigit function (p: 201)
  • C99 standard (ISO/IEC 9899:1999):
  • 7.4.1.5 The isdigit function (p: 182)
  • C89/C90 standard (ISO/IEC 9899:1990):
  • 4.3.1.4 The isdigit function

See also

checks if a wide character is a digit
(function) [edit]
C++ documentation for isdigit