What is calling and called function in C programming

Follow by Email
Facebook0
Facebook
Google+
https://codingsec.net/2016/12/calling-called-function-c-programming/

The point at which the function is being invoked or called is known as the calling function. The function which is being executed due to the function call is known as the called function. Example for both calling function and the called function is given in the above example.

Formal Parameters and Actual Parameters

A parameter or argument is data which is taken as input or considered as additional information by the function for further processing. There are two types of parameters or arguments. The parameters which are passed in the function call are known as actual parameters or actual arguments. The parameters which are received by the called function are known as formal parameters or formal arguments. Example is shown below:

Classification of Functions

Based on the parameters and return values, functions can be categorized into four types. They are:

  1. Function without arguments and without return value.
  2. Function without arguments and with return value.
  3. Function with arguments and with return value.
  4. Function with arguments and without return value.

Function without arguments and without return value

In this type of functions there are no parameters/arguments in the function definition and the function does not return any value back to the calling function. Generally, these types of functions are used to perform housekeeping tasks such as printing some characters etc.

Example:

In the above example, printstars function does not have any parameters. Its task is to print 20 stars whenever it is called in a program. Also printstarsfunction does not return any value back.

Function without arguments and with return value

In this type of functions, the function definition does not contain arguments. But the function returns a value back to the point at which it was called. An example for this type of function is given below:

Example:

In the above example, readint function has no parameters/arguments. The task of this function is to read a integer from the keyboard and return back to the point at which the function was called.

Function with arguments and with return value

In this type of functions, the function definition consists of parameters/arguments. Also, these functions returns a value back to the point at which the function was called. These types of functions are the most frequently used in programming. An example for this type of function can be seen below:

Example:

In the above example, the function add consists of two arguments or parameters x and y. The function adds both x and y and returns that value stored in the local variable result back to the point at which the function was called.

 

Take your time to comment on this article.

Follow by Email
Facebook0
Facebook
Google+
https://codingsec.net/2016/12/calling-called-function-c-programming/

Add a Comment

Your email address will not be published. Required fields are marked *

Like the article? please consider sharing it. Thank you

Advertisment ad adsense adlogger