English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The isalpha() function checks if a character is an alphabet.
In C programming, the isalpha() function checks if a character is an alphabet (a-z and A-Z).
If the character passed to isalpha() is an alphabet, it returns a non-zero integer, otherwise it returns 0.
The isalpha() function is in<ctype.h>Defined in header files.
int isalpha(int argument);
The function isalpha() accepts a single parameter in integer form and returns an integer value.
Even if isalpha() is passed an integer as a parameter, the character is passed to the isalpha() function.
Internally, the character is converted to its corresponding integer value based on its ASCII value when passed.
Return Value | Remarks |
---|---|
0 | If the parameter is not an alphabet. |
Non-zero number | If the parameter is an alphabet. |
#include <stdio.h> #include <ctype.h> int main() { char c; c = 'Q'; printf("\nResult when passing an uppercase letter: %d", isalpha(c)); c = 'q'; printf("\nResult when passing a lowercase letter: %d", isalpha(c)); c='+; printf("\nResult when passing a non-alphabetic character: %d", isalpha(c)); return 0; }
Output Result
Result when passing an uppercase letter: 1 Result when passing a lowercase letter: 2 Result when passing a non-alphabetic character: 0
Note:When an alphabetic character is passed to the isalpha() on the system, you get a different non-zero integer. However, when you pass a non-alphabetic character to isalpha(), it always returns 0.
#include <stdio.h> #include <ctype.h> int main() { char c; printf("Enter a character: "); scanf("%c", &c); if (isalpha(c) == 0) printf("%c is not a letter.", c); else printf("%c is a letter.", c); return 0; }
Output Result
Enter a character: 5 5 Not a letter.