Open In App

tolower() Function in C++

Last Updated : 11 Mar, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

The C++ tolower() function converts an uppercase alphabet to a lowercase alphabet. It is a predefined function of ctype.h header file. If the character passed is an uppercase alphabet, then the tolower() function converts an uppercase alphabet to a lowercase alphabet. This function does not affect another lowercase character, special symbol, or digit.

int tolower(int ch);

Parameter:

  • ch: It is the character to be converted to lowercase.

Return Value: This function returns the ASCII value of the lowercase character corresponding to the ch.

In C++, typecasting of int to char is done as follows:

char c = (char) tolower('A');

Below programs illustrate the tolower() function in C++:

Example 1:

C++
// C++ program to demonstrate
// example of tolower() function.

#include <iostream>
using namespace std;

int main()
{

    char c = 'G';

    cout << c << " in lowercase is represented as = ";

    // tolower() returns an int value there for typecasting
    // with char is required
    cout << (char)tolower(c);
}

Output
G in lowercase is represented as = g

Example 2:

C++
// C++ program to convert a string to lowercase
// using tolower
#include <bits/stdc++.h>
using namespace std;

int main()
{

    // string to be converted to lowercase
    string s = "GEEKSFORGEEKS";
  
    for (auto& x : s) {
        x = tolower(x);
    }
  
    cout << s;
    return 0;
}

Output
geeksforgeeks

Note:  If the character passed in the tolower() is any of these three

  1. lowercase character
  2. special symbol
  3. digit

tolower() will return the character as it is.

Example 3:

C++
// C++ program to demonstrate
// example of tolower() function.
#include <iostream>
using namespace std;

int main() {

    string s="Geeks@123";
  
      for(auto x:s){
      
          cout << (char)tolower(x);
    }
  
    return 0;
}

Output
geeks@123

Next Article
Article Tags :
Practice Tags :

Similar Reads