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:
Aspects of Function
A C function has three different characteristics:
The following is the syntax for creating a function in the C language:
In C programming, there are two different types of functions:
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.
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:
J ….. 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'.
0123456789 ………………. 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