C++ toupper()

The toupper() function in C++ converts a given character to uppercase.

toupper() Prototype

int toupper(int ch);

The toupper() function converts ch to its uppercase version if it exists. If the uppercase version of a character does not exist, it remains unmodified. The lowercase letters from a to z is converted to uppercase letters from A to Z respectively.

The behaviour of toupper() is undefined if the value of ch is not representable as unsigned char or is not equal to EOF.

It is defined in <cctype> header file.

toupper() Parameters

ch: The character to convert

toupper() Return value

The toupper() function returns a uppercase version of ch if it exists. Otherwise it returns ch.

Example: How toupper() function works

#include <cctype>
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main()
    char str[] = "John is from USA.";

    cout << "The uppercase version of \"" << str << "\" is " << endl;

    for (int i=0; i<strlen(str); i++)
    return 0;

When you run the program, the output will be:

The uppercase version of "John is from USA." is