The isupper() function defined in the ctype.h header file. It helps to check the specified character is an uppercase alphabet (A-Z) or not.
int isupper(int argument); #where argument will be a character
The isupper() function takes a single parameter and is in the form of an integer and the return value should be an integer. When a character is passed it is converted into the integer value corresponding to its ASCII value.
Parameter | Description | Required / Optional |
---|---|---|
argument | The character to be checked | Required |
If the given character is an uppercase alphabet, isupper() returns a non-zero integer else zero. When an uppercase alphabet character is passed we will get a different non-zero integer.
Input | Return Value |
---|---|
Zero | If the parameter isn't an uppercase alphabet |
Non zero number | If the parameter is an uppercase alphabet |
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch;
ch='A';
printf("If %c is passed to isupper(): %d", ch, isupper(ch));
c='a';
printf("\nIf %c is passed to isupper(): %d", ch, isupper(ch));
return 0;
}
Output:
If A is passed to isupper(): 1 If a is passed to isupper(): 0
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch;
printf("Please enter a character: ");
scanf("%c", &ch);
if (isupper(ch) == 0)
printf("The given %c is not an uppercase alphabet.", ch);
else
printf("The given %c is an uppercase alphabet.", ch);
return 0;
}
Output:
Please enter a character: H The given H is a uppercase alphabet.