Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
Understanding the toupper() Function
An Example of the toupper() Function
Key Points about the toupper() Function
Frequently Asked Questions
Can toupper() handle strings?
Does toupper() modify the original character?
Can toupper() convert special characters or numbers?
Last Updated: Mar 27, 2024

toupper() in C++

Author Gunjan Batra
0 upvote
Master Python: Predicting weather forecasts
Ashwin Goyal
Product Manager @


In C++, there are a plethora of built-in functions that significantly simplify coding tasks. Among these functions, the ones designed to manipulate characters and strings are quite useful. One such function is toupper(), a function designed to convert lowercase letters to uppercase. 

toupper() in C++


This article will explore the toupper() function in C++, discussing its use, demonstrating how it works, and addressing common questions about it.


Understanding the toupper() Function

The toupper() function is a standard library function in C++ that converts a lowercase letter to its uppercase equivalent. If the passed character is already in uppercase, or is not an alphabetic character, the function returns the character as it is.

Here is the syntax of the toupper() function:

int toupper(int c);

The toupper() function resides in the <cctype> header file, so you'll need to include it in your program to use the function:

#include <cctype>
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

An Example of the toupper() Function

Here's an illustrative example of the toupper() function:

#include <iostream>
#include <cctype>

int main() {
    char ch = 'g';
    std::cout << "Original character: " << ch << '\n';
    char upper_ch = toupper(ch);
    std::cout << "After toupper: " << upper_ch << '\n';
    return 0;


In the above program, the toupper() function is used to convert the lowercase letter 'g' to uppercase. The output of the program would be:


Key Points about the toupper() Function

When using toupper(), it's important to keep the following points in mind:

  • Argument: The toupper() function takes a single argument - an integer or a character to convert to uppercase.
  • Return Value: It returns the uppercase equivalent if the argument is a lowercase letter. Otherwise, it returns the argument as it is.
  • Non-Alphabetic Characters: If a non-alphabetic character is passed to toupper(), it will return the character unmodified.
  • Library: toupper() is part of the <cctype> library in C++.

Also see, Abstract Data Types in C++

Frequently Asked Questions

Can toupper() handle strings?

No, toupper() works on individual characters. To convert a whole string, you'd need to iterate over the string and convert each character individually.

Does toupper() modify the original character?

No, toupper() returns the converted character but does not modify the original one.

Can toupper() convert special characters or numbers?

No, toupper() only converts lowercase alphabetic characters to uppercase. Other characters are returned as they are.


The toupper() function in C++ is a handy tool when working with text data, especially when there's a need to convert characters to uppercase. It simplifies what could be a tedious task if done manually and contributes to writing more efficient and clean code. As with all tools, understanding its usage, strengths, and limitations is key to using it effectively. Happy coding!

Also read -  File Handling in CPP

Previous article
How to Install Turbo in C++
Next article
abs() in C++
Live masterclass