C Program to Check Whether a Character is an Alphabet or not

To understand this example, you should have knowledge of following C programming topics:

This program takes a character from user and checks whether that character is an alphabet or not.

Source Code to Check Character is an alphabet or not

/* C programming code to check whether a character is alphabet or not.*/

#include <stdio.h>
int main()
    char c;
    printf("Enter a character: ");
    if( (c>='a'&& c<='z') || (c>='A' && c<='Z'))
       printf("%c is an alphabet.",c);
       printf("%c is not an alphabet.",c);
    return 0;

Output 1

Enter a character: *
* is not an alphabet

Output 2

Enter a character: K
K is an alphabet

When a character is stored in a variable, ASCII value of that character is stored instead of that character itself. For example: If  'a' is stored in a variable, ASCII value of 'a' which is 97 is stored. If you see the ASCII table, the lowercase alphabets are from 97 to 122 and uppercase letter are from 65 to 90. If the ASCII value of number stored is between any of these two intervals then, that character will be an alphabet. In this program, instead of number 97, 122, 65 and 90; we have used 'a', 'z', 'A' and 'Z' respectively which is basically the same thing.

This program also can be performed using standard library function isalpha().