isalpha() in C

Overview
isalpha() is a function used to check whether the input character is an alphabet or not. It is present in the ctype header file in the C standard library.
Syntax of isalpha() in C
The syntax of isalpha is:
Parameters of isalpha() in C
The isalpha() function takes the following parameter as an input.
- c: a character or its ASCII value
Return Values of isalpha() in C
Return Type: int
The function returns different values depending on the input. They are as follows.
- If the character is an alphabet(lowercase or uppercase), it returns a non-zero number.
- If the character is not an alphabet, it returns zero.
Example of isalpha() in C
Output
What is isalpha() in C?
The isalpha() function in C is used to check whether a character is an alphabet or not. It is defined in the ctype header file in the C Standard Library.
It returns a non-zero number if it is an alphabet('a'-'z' and 'A'-'Z'). Else it returns zero for all other characters.
Note: To check whether the given character is an alphabet, the function converts the character into its ASCII value.
More Examples
Let's see some more examples to understand how this function works.
Example 1: Program to use isalpha() function for lowercase alphabets
Output
Explanation In the above program, a lowercase alphabet(a) is passed to the function isalpha(). It returns a non-zero number(1024). Hence, the character passed is an alphabet.
Example 2: Program to use isalpha() function for uppercase alphabets
Output
Explanation In the above program, a uppercase alphabet(Q) is passed to the function isalpha. It returns a non-zero number(1024). Hence, the character passed is an alphabet.
Example 3: Program to use isalpha() function for numbers
Output
Explanation In the above program, a digit(9) is passed to the function isalpha. It returns zero. Hence, the character passed is not an alphabet.
Example 4: Program to use isalpha() function for special characters
Output
Explanation In the above program, a special character(*) is passed to the function isalpha. It returns zero. Hence, the character passed is not an alphabet.
Example 5: Program to use isalpha() function by passing ASCII values of characters.
Output
Explanation In this example, we pass the ASCII value of 'm'(ASCII value = 109) and '-'(ASCII value = 45) to the function. It returns the expected output.
Conclusion
- The isalpha() function is defined in the ctype header file in the C standard library.
- It is used to check whether a character is an alphabet or not.
- It returns a non-zero if the character is an alphabet and zero otherwise.