isdigit() Test whether a character is a decimal digit
isdigit() Test whether a character is a decimal digit
isdigit() returns nonzero for decimal digits 0-9. Pass EOF or unsigned char; it tests one character, not an integer, and cannot decode UTF-8 digits.
| Category | ctype.h character classes |
|---|---|
| Kind | Library function |
| Header | <ctype.h> |
| C standard | C89 / C90 |
📝 Syntax
int isdigit(int c);
⚙️ Parameters
| c Required | The character to test, represented as an unsigned char value or EOF. |
|---|
Returns: Returns a nonzero value for a decimal digit and zero otherwise.
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
Digits: 3
⚠️ Warning Passing a negative plain char value causes undefined behavior. Convert to unsigned char as shown; EOF may be passed directly.
💡 Tip isdigit() classifies a character, not an integer's numeric meaning: character '4' matches, whereas integer 4 is not the character '4'.
🏷️ Related ctype.h functions
📚 Related Tutorials
❓ FAQ
QCan isdigit determine whether an integer has multiple digits?
ANo. It tests one character at a time. To validate an entire numeric string, iterate through its characters or parse it and inspect the end pointer.
QDo isdigit('4') and isdigit(4) produce the same result?
ANo. '4' is a digit character and produces nonzero; the control character with value 4 is not a decimal digit and normally produces zero.
QCan isdigit recognize full-width digits or other Unicode digits?
ANot directly. Portable narrow-character classification guarantees only 0 through 9 from the basic character set. UTF-8 full-width digits consist of multiple bytes, so byte-by-byte calls do not provide complete Unicode digit classification. Decode such text first, then use a library that supports Unicode categories.