islower() function in C++

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

1. islower() Function Overview

The islower() function is part of the C++ <cctype> library. It checks if the given character is a lowercase alphabetic letter (a-z).

Signature:

int islower(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(islower(ch1)) {
        std::cout << "ch1 is a lowercase alphabetic letter." << std::endl;
    } else {
        std::cout << "ch1 is not a lowercase alphabetic letter." << std::endl;
    }

    if(islower(ch2)) {
        std::cout << "ch2 is a lowercase alphabetic letter." << std::endl;
    } else {
        std::cout << "ch2 is not a lowercase alphabetic letter." << std::endl;
    }

    return 0;
}

Output:

ch1 is a lowercase alphabetic letter.
ch2 is not a lowercase alphabetic letter.

3. Explanation

In this example, the islower() function is used to determine whether a character is a lowercase letter. 

The character 'g' is lowercase, so for ch1, the function returns true. 

On the other hand, ch2 contains the uppercase character 'M', hence for ch2, it returns false.


Comments