Javatpoint Logo
Javatpoint Logo

Putchar() function in C

A big program may be broken down into the fundamental components known as function in C. The group of code blocks denoted by is present in the function. Blocks of code called functions are set up in a program to carry out certain tasks. Functions can be utilized several times after just needing to be declared once in the application. Moreover, this increases code modularity and readability while also enabling code reuse.

The C program may be reused and made modular by calling a function numerous times. In other terms, we may argue that a program is made up of a group of functions. In some programming languages, the function is also known as a process or a subroutine.

Benefits of C functions

The benefits of C functions are as follows:

  • We may avoid repeatedly writing the same logic or code in a program by utilizing functions.
  • C functions can be called from anywhere in a program and at any number of times.
  • When a huge C program is broken up into several functions, we can simply follow it.
  • The primary accomplishment of C functions is reusability.
  • Yet in a C application, invoking functions always adds overhead.

Aspects of Function

A C function has three different characteristics:

  • Function announcement In order to inform the compiler of the function name, function arguments, and return type, a function must be declared globally in a c program.
  • Using a function throughout the program, functions can be invoked from anywhere. Function declaration and function calling cannot have different argument lists. The number of functions that must be sent must match the number indicated in the function declaration.
  • Define the function the actual statements that must be executed are included there. The most crucial component is the one over which the function has control. Here, it is important to note that the function can only return one value.
SN C function aspects Syntax
1 Function declaration return_type function_name (argument list);
2 Function call function_name (argument_list)
3 Function definition return_type function_name (argument list) {function body;}

The following is the syntax for creating a function in the C language:

Different Functions

In C programming, there are two different types of functions:

  • The functions that are specified in the C header files as libraries include scanf(), printf(), gets(), puts(), ceiling(), floor(), and many others.
  • User-defined functions are those that a C programmer creates so that they may be used repeatedly. It streamlines the code and lessens the complexity of a large application.

Return Value

Depending on the function, a C function could or might not return a value. Use void as the return type if the function doesn't need to return any values.

Let's look at a straightforward C function example that doesn't provide a value.

Use any data type, such as int, long, char, etc., if you wish the function to return any value. The value that the function will return determines the return type.

Let's look at a straightforward C function example that outputs an int value.

The return type in the example above is int since we must return 10 as a value. Use float as the method's return type if you wish to return a floating-point value, such as 10.2, 3.1, 54.5, or another number of that type.

To obtain the function's value, you must now call the function.

Various characteristics of invoking functions

An argument may or may not be accepted by a function. It could or might not give back any value. These facts lead to the conclusion that function calls have four different characteristics.

  • Without return value and without arguments
  • Function with a return value and no parameters
  • Function that takes parameters but doesn't return anything
  • Function that has parameters and a result

To write a character of the unsigned char type to stdout in C, use the putchar(int char) method. The parameter to this method is this character.


Parameter: The character that will be printed to stdout, char, is a required argument for this procedure.

Return Value: As an unsigned char, this function returns the character that was printed to stdout. In the event of a mistake, it also returns EOF.

The putchar() function is used in the examples that follow:


Process executed in 0.11 seconds
Press any key to continue


In the above example of program in C, as we can see we have initialized character 'ch' to 'J', after that we have called putchar function and we get the output as we expected to be that is character 'J'.

Another example:


Process executed in 0.12 seconds
Press any key to continue.


In the above example of program in C, as we can see we have initialized character 'ch' to '0', after that we have called putchar function in a for loop and we get the output as we expected to be that is character '0123456789'.

Next TopicQuick Sort in C

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA