Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

isdigit — C23 character classification function

`isdigit(c)` from `<ctype.h>` tests whether `c` is a decimal digit from the basic execution character set: one of `0` through `9`. It returns a nonzero value for a digit and zero for every other valid argument.

Version: C23

Syntax

int isdigit(int c);

isdigit(c) from <ctype.h> tests whether c is a decimal digit from the basic execution character set: one of 0 through 9. It returns a nonzero value for a digit and zero for every other valid argument.

The example passes 0, 9, A, and space and normalizes responses with != 0. Result 1 1 0 0 demonstrates both ends of the decimal range and rejection of a letter and spacing character; the nonzero result must not be assumed to equal exactly 1.

The argument must be EOF or representable as unsigned char; a negative plain char has undefined behavior. For a byte use isdigit((unsigned char)ch), but do not convert EOF. This function recognizes one-byte decimal digits, not every Unicode digit; numeric parsing must additionally handle signs, separators, and overflow.

Examples

#include <ctype.h>
#include <stdio.h>
int main(void){int values[]={'0','9','A',' '};printf("%d %d %d %d\n",isdigit(values[0])!=0,isdigit(values[1])!=0,isdigit(values[2])!=0,isdigit(values[3])!=0);return 0;}

Result

1 1 0 0

The example passes `0`, `9`, `A`, and space and normalizes responses with `!= 0`. Result `1 1 0 0` demonstrates both ends of the decimal range and rejection of a letter and spacing character; the nonzero result must not be assumed to equal exactly `1`.

Sources