isalpha() Test whether a character is alphabetic
isalpha() Test whether a character is alphabetic
isalpha() returns nonzero for a letter in the current locale. Pass EOF or unsigned char; it does not decode UTF-8, and true need not equal 1.
| Category | ctype.h character classes |
|---|---|
| Kind | Library function |
| Header | <ctype.h> |
| C standard | C89 / C90 |
📝 Syntax
int isalpha(int c);
⚙️ Parameters
| c Required | The character to test, represented as an unsigned char value or EOF. |
|---|
Returns: Returns a nonzero value if the character is alphabetic, and zero otherwise.
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
Letters: 1
⚠️ Warning Passing a potentially negative plain char value causes undefined behavior; the example converts it to unsigned char first.
💡 Tip Classification functions return zero or nonzero; do not assume a true result is exactly 1.
🏷️ Related ctype.h functions
📚 Related Tutorials
❓ FAQ
QWhy is isalpha often called as isalpha((unsigned char)c)?
AThe standard accepts only values representable as unsigned char, or EOF. On platforms with signed plain char, a negative value passed directly falls outside that domain.
QCan isalpha produce different results in different locales?
AYes. Alphabetic classification depends on the current locale. The default C locale guarantees A-Z and a-z, while other locales may classify additional characters as letters.
QCan isalpha directly classify a UTF-8 Chinese character or a complete wide character?
ANo. isalpha handles one value at a time, either EOF or a value representable as unsigned char; a multibyte UTF-8 sequence cannot be passed as one complete character. For wide characters, consider iswalpha() under an appropriate locale. When you need the full Unicode letter database and cross-platform consistency, use a dedicated Unicode library.