In isalnum()
is used to check if the input value is either an alphabet or a number.
int isalnum(char ch);
ch
: a character of type char
.
char
in C++ is a special type of datatype that deals with alphabet values. From a memory perspective, C++char
is of 1 byte.
Nonzero
: if the argument values are in the range (a-z
,A-Z
,0-9
), then isalnum
returns a non-zero value, i.e., TRUE
.
0
: if the argument is not between the defined range(a-z
,A-Z
,0-9
), then isalnum
returns 0, i.e., FALSE
.
In the example below, we pass the English alphabet a
as an argument, which returns a non-zero value.
#include <iostream>using namespace std;int main() {int num = isalnum('a');if (num) {cout << "TRUE at " << num;} elsecout << "FALSE at " << num;return 0;}