Skip to main content

Types of Function in C Programming Language

C Programming language
In my previous C programming tutorial I tried to explain what the function is, its advantages, how you can declare a function C and call a function in your program C. And I told you that there are five types of functions and they are:
1. Functions without arguments and without return values.
2. Functions with arguments and without return values.
3. Functions with arguments and return values.
4. Functions that return multiple values.
5. Functions without arguments and return values.
1. Functions without arguments and without return value.
A C function without arguments means that you can not pass data (values ​​such as int, char, etc.) to the called function. Similarly, the function without type of return does not return data to the call function. It is one of the simplest types of functions in C. This type of function that does not return any value can not be used in an expression, it can only be used as an independent instruction. Let's have an example to illustrate this.

Explanation of the source code:
The example of the previous C program illustrates how to declare a function without an argument and without a return type. I will explain only the important lines just because this example of the C program is for those who are above the beginner level.
Line 4-13: This C code block is a user defined function (UDF) whose task is to print a horizontal line. This is a simple function and a basic programmer can understand this. As you can see on the line no. 8 I have declared a "for loop" that rotates 30 times and prints the "-" symbol continuously.
Line 15-23: These lines are "main ()" function code block. Line 18 and 20 simply prints two different messages. And the line does not. 19 and 21 call our user-defined function "printline ()". You can see the output of this program below


2. Functions with arguments and no return value.
In our previous example, we have noticed that the "main ()" function has no control over the "printfline ()" UDF, it can not control its output. When "main ()" calls "printline ()", it simply prints the line each time. Then the result remains the same

A C function with arguments can work much better than the previous function type. This type of function can accept data from the call function. In other words, it sends data to the function called from the call function, but can not send result data to the call function. On the contrary, it shows the result in the terminal. But we can control the output of the function by providing several values ​​as arguments. Let's see an example to improve it.

Explanation of the source code:
This program simply sends two integers to the UDF "add ()" which, in addition, calculates its sum and stores it in another variable and then prints that value. It is such a simple program to understand.
Line 4-9: this block of code C is "add ()" that accepts two arguments of type integer. This UDF also has a "result" of an integer variable that stores the sum of the values ​​passed by the call function (in this example "main ()"). And the line does not. 8 simply prints the result together with argument variable values.
Line 11-18: this block of code is a "main ()" function, but only the line does not. 14, 15, 16 is important for us now. In these three lines we have called the same function "add ()" three times but with different values ​​and each function call gives different output. So, you can see, we can control the output of the function by providing different integer parameters that were not possible in the type 1 function. This is the difference between "function without argument" and "function with argument".
Functions with arguments and without return value.
• Call by value and call by reference in programming C
This example C is a good example of functions with arguments and no return value. Please take a look to better understand this concept.
3. Functions with arguments and return value.
This type of function can send arguments (data) from the call function to the called function and wait for the result to be returned from the function called to the call function. And this type of function is used mainly in the world of programming because it can make bidirectional communications; can accept data as arguments and can also return data as a return value. The data returned by the function can be used later in our program to perform more calculations.

Explanation of the source code:
This program sends two integer values ​​(x and y) to the UDF function "add ()", "add ()" adds these two values ​​and returns the result to the call function (in this program the function "main ()") The subsequent result is printed on the terminal.

Line No. 4-9: Look at line no. 4 carefully, start with int. This int is the return type of the function

Comments

Popular posts from this blog

How to Activate Windows 7 & 8 for Free

If one day your personal computer starts to act and questions your Windows activation status, you may have to prepare for a series of activation settings. Your preferred and optional fixes may involve getting help from Microsoft support services and using the Daz loader and other pirated tools. If you choose to adjust your system using the latter option, keep in mind that Microsoft will install Windows Activation Technologies to counteract them.
Examples of Windows Genuine Advantage (WGA) pop-up windows include: • This copy of Windows is not original • You may be the victim of a software counterfeit Previous and similar notifications can happen due to the following: • The original Windows installation may have disappeared for one reason or another. This even when you have purchased an original copy of the Windows installation DVD. You probably did not follow the activation instructions to the point and now you are paying the price. • Or maybe he was scammed and bought an illegal copy of Windo…

Best PC Gaming Ram 2018 DDR3 Memory Reviews

Have you ever wondered which is the best or most popular ram for games in a particular year? In this post, I will take a look at what most consumers think, as well as my opinion on which ram gives the best value for your money. In addition, I have written a guide for everything you need to know about memory, as well as where you can go to see which ram is the most durable and has the lowest RMA rates. Before you leave, do not forget to participate in the open discussion area below.
Top 10 best rated PC RAM / memory for games When it comes to ram players, they look for stability, reliability, speed and the best overall value for their money. This list of the top ten is based on customer comments, ratings and, most importantly, your comments in the voting section. If you need to know if this ram is compatible with your motherboard, see the section of the learning guide below and the specifications of your motherboard. If you're building a PC, then make sure you buy ram completely so you…

Beginner's Guide to the Best USB DAC Headphone Amps, 2016-2017

Even very good sound cards need a little help to convert digitally stored music into a high-quality, genuine sound.
If you store most of your music on a Mac or PC, a special digital-to-analog converter will go a long way in making it worthwhile to invest in a good pair of headphones.
Whatever your heart's desire, from a concert hall experience to a full beat festival, a good conversion will bring your digitally stored music to life.
Even MP3 files on your phone or tablet will lose less "loss". The compression results of lost files can produce a watery sound and reduce the dynamic range of the audio. A DAC helps fill in the gaps.
Do you want more than just a music amplifier?
Many people will want to use a digital-to-analog converter amplifier to get the best sound from movies and videos. The sounds of a cable box get a big boost in quality. The sound of the game console can be greatly improved.
Portable units for smart devices
Portable DACs have been the big area of growth in re…