isupper() function in C++

In this guide, you will learn what is isupper() function is in C++ programming and how to use it with an example.

1. isupper() Function Overview

The isupper() function is part of the C++ <cctype> library. It checks if the given character is an uppercase alphabetic letter (A-Z).

Signature:

int isupper(int ch);

Parameters:

- ch: The character to be checked. Although it's an int, it essentially represents the ASCII value of the character.

2. Source Code Example

#include <iostream>
#include <cctype>

int main() {
    char ch1 = 'G';
    char ch2 = 'm';

    if(isupper(ch1)) {
        std::cout << "ch1 is an uppercase alphabetic letter." << std::endl;
    } else {
        std::cout << "ch1 is not an uppercase alphabetic letter." << std::endl;
    }

    if(isupper(ch2)) {
        std::cout << "ch2 is an uppercase alphabetic letter." << std::endl;
    } else {
        std::cout << "ch2 is not an uppercase alphabetic letter." << std::endl;
    }

    return 0;
}

Output:

ch1 is an uppercase alphabetic letter.
ch2 is not an uppercase alphabetic letter.

3. Explanation

In this example, the isupper() function is used to determine whether a character is an uppercase letter. 

The character 'G' is uppercase, so for ch1, the function returns true.

On the other hand, ch2 contains the lowercase character 'm', hence for ch2, it returns false.


Comments