C isalpha()

The isalpha() function checks whether a character is an alphabet or not.

In C programming, isalpha() function checks whether a character is an alphabet (a to z and A-Z) or not.

If a character passed to isalpha() is an alphabet, it returns a non-zero integer, if not it returns 0.

The isalpha() function is defined in <ctype.h> header file.


C isalpha() Prototype

int isalpha(int argument);

Function isalpha() takes a single argument in the form of an integer and returns an integer value.

Even though, isalpha() takes integer as an argument, character is passed to isalpha() function.

Internally, the character is converted into the integer value corresponding to its ASCII value when passed.


isalpha() Return Value

Return Value Remarks
Zero (0) If the parameter isn't an alphabet.
Non zero number If the parameter is an alphabet.

Example: C isalpha() function

#include <stdio.h>
#include <ctype.h>
int main()
{
    char c;
    c = 'Q';
    printf("\nResult when uppercase alphabet is passed: %d", isalpha(c));

    c = 'q';
    printf("\nResult when lowercase alphabet is passed: %d", isalpha(c));

    c='+';
    printf("\nResult when non-alphabetic character is passed: %d", isalpha(c));

    return 0;
}

Output

Result when uppercase alphabet is passed: 1
Result when lowercase alphabet is passed: 2
Result when non-alphabetic character is passed: 0

Note: You can get a different non-zero integer when alphabetic character is passed to isalpha() on your system. But, when you pass non-alphabetic character to isalpha(), it always returns 0.


Example: C Program to Check whether a Character Entered by User is Alphabet or not

#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 an alphabet.", c);
    else
         printf("%c is an alphabet.", c);

    return 0;
}

Output

Enter a character: 5
5 is not an alphabet.