What is isalnum() in C++?

In C++Object-Oriented Programming Language, isalnum() is used to check if the input value is either an alphabet or a number.

Syntax

int isalnum(char ch);

Parameters

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.

Return value

  • 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.

Code

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;
} else
cout << "FALSE at " << num;
return 0;
}

Free Resources