ToLOWER In C++OverviewThe tolower C++ function is defined in the cctype header file. The tolower C++ method converts an uppercase letter into an equivalent lowercase letter when an uppercase character is given into the function. Syntax:We will use the following syntax in a C++ program to use the tolower() method: Declared as: C++ tolower parameters in the cctype header file () C++ parameters of tolower()The tolower C++ function requires a character as a parameter, which must be converted to an equivalent lowercase character. In the more basic C++ technique, the character parameter is automatically type-cast to the int type (the character's ASCII value). Return Value of C++ tolower()The tolower C++ function returns: Returns the ASCII value for the argument's lowercase equivalent character for the Alphabet parameter (a-z, A-Z). Returns the argument's ASCII value directly for non-alphabets. Non-alphabets can be anything that isn't an alphabet, such as special characters (%, &, @, etc.), numerical values (1, 2, 6, etc.), or special characters. Tolower() Function Undefined BehaviorIf the argument's value is neither an unsigned char nor EOF, the tolower() C++ function's behaviour is undefined. Examples of C++ functions for tolower()Let's examine how the tolower C++ function is implemented in some sample C++ programs. With Type Conversion, tolower() Using the tolower C++ method in the C++, two alphabets are being converted from uppercase to lowercase while two non-alphabets are being left alone. For Example: Output p q 7 @ Explanation: We have declared and initialized four char variables in the above program. The above program converts uppercase characters into lowercase characters using the tolower C++ function. Since the tolower() function delivers the ASCII codes for the comparable lowercase characters, we have printed the lowercase characters by typecasting its return value to the char type. Without Type Conversion, tolower()Using the tolower C++ functiton, we are changing the case of four alphabets from upper to lower without type conversion. For Example: Output 98 121 50 64 Explanation: We have declared and initialized four char variables in the above program. In the program, we are converting the uppercase characters into lowercase characters using the tolower C++ function, but we are not type-casting the value that the tolower function returns, which is the equivalent ASCII value. As a result, the result we obtain is the equivalent ASCII code for the relevant values of the char variables. Tolower() Using a StringThe tolower C++ function is used in the below program to change a complete string (char array) into a lowercase string. For Example: Output this string is mixed with upper and lower case "Saswat is from the INDIA" it is pure lower case string: "saswat is from the india" Explanation: A char array has been declared and initialized in the above program. The above program converts all of the string's uppercase characters into lowercase characters using the tolower C++ function and for loop. The output includes the mixed upper- and lowercase string as well as the entire lowercase string. Conclusion
Next TopicUNORDERED_MAP IN C++ |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India