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.

Categoryctype.h character classes
KindLibrary function
Header<ctype.h>
C standardC89 / C90

📝 Syntax

int isdigit(int c);

⚙️ Parameters

c RequiredThe 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 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏