The Wayback Machine - https://web.archive.org/web/20240527085854/https://www.geeksforgeeks.org/toupper-function-in-c/
Open In App

toupper() function in C

Last Updated : 04 Aug, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The toupper() function is used to convert lowercase alphabet to uppercase. i.e. If the character passed is a lowercase alphabet then the toupper() function converts a lowercase alphabet to an uppercase alphabet. It is defined in the ctype.h header file.
Syntax: 
 

int toupper(int ch);

Parameter: It accepts a single parameter: 

  • ch: This represents the character to be converted to uppercase.

Returns: This function returns the uppercase character corresponding to the ch.
Below programs illustrate the toupper() function in C:
Example 1:- 

c




// C program to demonstrate
// example of toupper() function.
#include <ctype.h>
#include <stdio.h>
 
int main()
{
    char ch;
 
    ch = 'g';
    printf("%c in uppercase is represented as  %c",
           ch, toupper(ch));
 
    return 0;
}


Output: 

g in uppercase is represented as  G

 

Example 2:- 

C




// C program to demonstrate
// example of toupper() function.
#include <ctype.h>
#include <stdio.h>
 
int main()
{
    int j = 0;
    char str[] = "geekforgeeks\n";
    char ch;
 
    while (str[j]) {
        ch = str[j];
        putchar(toupper(ch));
        j++;
    }
 
    return 0;
}


Output: 

GEEKFORGEEKS

 

Note:  

 If the character passed in the toupper() is any of these three

1. uppercase character

2. special symbol

3. digit

toupper() will return the character as it is.
                      

Example :

C




// C program to demonstrate
// example of toupper() function.
#include <ctype.h>
#include <stdio.h>
 
int main()
{
    int j = 0;
    char str[] = "GeEks@123\n";
    char ch;
 
    while (str[j]) {
        ch = str[j];
        putchar(toupper(ch));
        j++;
    }
 
    return 0;
}
// code is contributed by codersaty


Output:

GEEKS@123



Similar Reads

C Function Arguments and Function Return Values
Prerequisite: Functions in C A function in C can be called either with arguments or without arguments. These functions may or may not return values to the calling functions. All C functions can be called either with arguments or without arguments in a C program. Also, they may or may not return any values. Hence the function prototype of a function
6 min read
How to call function within function in C or C++
When we begin programming in C/C++, we generally write one main() function and write all our logic inside this. This approach is fine for very small programs, but as the program size grows, this become unmanageable. So we use functions. We write code in the form of functions. The main function always acts as a driver function and calls other functi
3 min read
Returning a function pointer from a function in C/C++
In C/ C++, like normal data pointers(int *, char *, etc), there can be pointers to functions. Every function created in a program gets an address in memory since pointers can be used in C/C++, so a pointer to a function can also be created. Syntax: return type (*function_pointer_name) (argument_type_1, argument_type_2, ......, argument_type_n) =
6 min read
Write a one line C function to round floating point numbers
Algorithm: roundNo(num) 1. If num is positive then add 0.5. 2. Else subtract 0.5. 3. Type cast the result to int and return. Example: num = 1.67, (int) num + 0.5 = (int)2.17 = 2 num = -1.67, (int) num - 0.5 = -(int)2.17 = -2 Implementation: /* Program for rounding floating point numbers */ # include&lt;stdio.h&gt; int roundNo(float num) { return nu
1 min read
Does C support function overloading?
First of all, what is function overloading? Function overloading is a feature of a programming language that allows one to have many functions with same name but with different signatures. This feature is present in most of the Object Oriented Languages such as C++ and Java. But C doesn't support this feature not because of OOP, but rather because
2 min read
How can I return multiple values from a function?
We all know that a function in C can return only one value. So how do we achieve the purpose of returning multiple values. Well, first take a look at the declaration of a function. int foo(int arg1, int arg2); So we can notice here that our interface to the function is through arguments and return value only. (Unless we talk about modifying the glo
2 min read
How to declare a pointer to a function?
While a pointer to a variable or an object is used to access them indirectly, a pointer to a function is used to invoke a function indirectly. Well, we assume that you know what it means by a pointer in C. So how do we create a pointer to an integer in C? Huh..it is pretty simple... int *ptrInteger; /*We have put a * operator between int and ptrInt
2 min read
Can We Call an Undeclared Function in C++?
Calling an undeclared function is a poor style in C (See this) and illegal in C++and so is passing arguments to a function using a declaration that doesn't list argument types.If we call an undeclared function in C and compile it, it works without any error. But, if we call an undeclared function in C++, it doesn't compile and generates errors. In
2 min read
What is evaluation order of function parameters in C?
It is compiler dependent in C. It is never safe to depend on the order of evaluation of side effects. For example, a function call like below may very well behave differently from one compiler to another: void func (int, int); int i = 2; func (i++, i++); There is no guarantee (in either the C or the C++ standard language definitions) that the incre
1 min read
Can We Use Function on Left Side of an Expression in C and C++?
In C, it is not possible to have function names on the left side of an expression, but it's possible in C++. How can we use the function on the left side of an expression in C++? In C++, only the functions which return some reference variables can be used on the left side of an expression. The reference works in a similar way to pointers, so whenev
1 min read