C++ cctype isalnum() Function
Example
Check if a character is a letter or a digit:
char c = '7';
if (isalnum(c)) {
cout << c << " is a letter or a digit";
} else {
cout << c << " is not a letter or a digit";
}
Definition and Usage
The isalnum() function checks if a character is a letter (A to Z, or a to z) or a digit (0 to 9).
It returns a non-zero number (true) if it is, and 0 (false) if it is not. Spaces and punctuation marks, like ! and ?, are not letters or digits.
The isalnum function is defined in the <cctype> header file.
Tip: Use isalpha() to check for letters only, and isdigit() to check for digits only.
Syntax
int isalnum(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 or a digit, otherwise 0 (false). |
|---|
Related Pages
Read more about strings in our Strings Tutorial.