Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Syntax 
3.
Example
3.1.
Example 1
3.2.
Example 2
4.
Frequently Asked Questions
4.1.
Which header file is used for the tolower() function?
4.2.
What is the return type of the tolower() function?
4.3.
What happens when a lowercase character is passed as an argument?
4.4.
What happens when a special character is passed as an argument?
4.5.
What happens when a string is passed as an argument?
5.
Conclusion
Last Updated: Mar 27, 2024

tolower() function in C

Introduction

The tolower() method turns an uppercase alphabet to a lowercase letter. If the tolower() method is supplied inputs that are not uppercase alphabets, it returns the same character that was passed to the function. It is specified in the header file ctype.h.

Also Read About, Sum of Digits in C, C Static Function

Syntax 

int tolower(int argument);

In C programming, the character is saved as an integer. When a character is supplied as an argument, the character's matching ASCII value (integer) is passed instead of the character itself.

Example

Example 1

Let's take an example to understand the toLower() function by passing an uppercase, a lowercase and a special symbol as a parameter to the toLower() function.

#include <stdio.h>
#include <ctype.h>
int main()
    char c, result;

    c = 'A';
    result = tolower(c);
    printf("%c\n", result);

    c = 'a';
    result = tolower(c);
    printf("%c\n", result);

    c = '$';
    result = tolower(c);
    printf("%c\n", result);

    return 0;
}

Output:

a
a
$ 

Example 2

Let's take a look at one more example to understand the toLower() function.

#include<stdio.h>
#include <ctype.h> 

int main() 
{ 
	char ch; 
	ch = 'P'; 

	printf("%c in lowercase is %c", 
	ch, tolower(ch)); 

	return 0; 
} 


Output   
P in lowercase is p


You can also read about C dynamic array, Tribonacci Series and  Short int in C Programming

Frequently Asked Questions

Which header file is used for the tolower() function?

tolower() function is defined in ctype.h” header file which is included for converting any uppercase letter to lowercase.

What is the return type of the tolower() function?

The tolower() function returns a character type, as tolower() function is used for converting characters.

What happens when a lowercase character is passed as an argument?

If a lowercase character is passed into a tolower() function as an argument, then the same character is returned, and no case conversion happens.

What happens when a special character is passed as an argument?

If a special character is passed into a tolower() function as an argument, then the same character is returned, and no case conversion happens.

What happens when a string is passed as an argument?

If a string is passed into a tolower() function as an argument, then the last character of the string is returned in lowercase, and the case conversion is done.

Conclusion

In this article, we had a look at tolower() function in C and also learned its operation. We hope that this blog has helped you enhance your knowledge of tolower() function, and if you would like to learn more, check out our String functions articles on Coding Ninjas Studio. Do upvote our blog to help other ninjas grow. Happy Coding!!

Live masterclass