C++ cctype isalpha() Function
Example
Check if a character is a letter:
char c = 'W';
if (isalpha(c)) {
cout << c << " is a letter";
} else {
cout << c << " is not a letter";
}
Definition and Usage
The isalpha() function checks if a character is a letter, from A to Z or from a to z.
It returns a non-zero number (true) if it is, and 0 (false) if it is not. Digits, spaces and punctuation marks are not letters.
The isalpha function is defined in the <cctype> header file.
Tip: Use isupper() or islower() to check if a letter is uppercase or lowercase.
Syntax
int isalpha(int c);
Parameter Values
| Parameter | Description |
|---|---|
| c | Required. The character to check. |
Technical Details
| Returns: | An int value. Non-zero (true) if the character is a letter, otherwise 0 (false). |
|---|
Related Pages
Read more about strings in our Strings Tutorial.