isalnum function > ctype.h > header files in c Programming

isalnum function > ctype.h > header files in c Programming

Syntax int isalnum (int c)
Header File ctype.h
Return Value
  • Return non-zero if letter is either alphabet or digit
  • Return zero if character is not alphanumeric

Live Example :


void main()
{
char ch = '1';

if(isalnum(ch))

printf("nThis is alpha-numeric character");

else

printf("nThis is non alpha-numeric character");
}



Output : 
This is alpha-numeric character

Following are alph-numeric character :
  1. Uppercase Letters [ A-Z]
  2. Lowercase Letters [a-z]
  3. Digits [0-9]
Explanation of statement : if(isalnum(ch))
  1. character ch is passed to function isalnum 
  2. if ch belongs to the set of alpha-numeric character then it returns positive value 
  3. otherwise it returns zero .
Note : 
  1. Positive non-zero value given to if block , will result in TRUE condition
  2. Zero value given to if block , will result in FALSE condition

Question How we are passing character value to function , which contradicts to the Given Syntax ?
Answer
We are passing character to function , automatically gets converted into (int) equivalent ascii value  


    Bookmark & Share