Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Firefox https://www.programiz.com/c-programming/library-function/ctype.

h/isalnum

C isalnum()
The isalnum() function checks whether the argument
passed is an alphanumeric character (alphabet or
number) or not.

The function definition of isalnum() is:

int isalnum(int argument);

It is defined in the ctype.h (/c-programming/library-


function/ctype.h) header file.

isalnum() Parameters

• argument - a character

isalnum() Return Value

• Returns 1 if argument is an alphanumeric character.

• Returns 0 if argument is neither an alphabet nor a


digit.

Example #1: isalnum() function return value

1 of 3 9/9/2022, 10:19 PM
Firefox https://www.programiz.com/c-programming/library-function/ctype.h/isalnum

#include <stdio.h>
#include <ctype.h>
int main()
{
char c;
int result;

c = '5';
result = isalnum(c);
printf("When %c is passed, return value is %d\n", c, result);

c = 'Q';
result = isalnum(c);
printf("When %c is passed, return value is %d\n", c, result);

c = 'l';
result = isalnum(c);
printf("When %c is passed, return value is %d\n", c, result);

c = '+';
result = isalnum(c);
printf("When %c is passed, return value is %d\n", c, result);

return 0;
}

Output

When 5 is passed, return value is 1


When Q is passed, return value is 1
When l is passed, return value is 1
When + is passed, return value is 0

Example #2: Check if a character is an


alphanumeric character

2 of 3 9/9/2022, 10:19 PM
Firefox https://www.programiz.com/c-programming/library-function/ctype.h/isalnum

#include <stdio.h>
#include <ctype.h>
int main()
{
char c;
printf("Enter a character: ");
scanf("%c", &c);

if (isalnum(c) == 0)
printf("%c is not an alphanumeric character.", c);
else
printf("%c is an alphanumeric character.", c);

3 of 3 9/9/2022, 10:19 PM

You might also like