What are the formal and actual parameters in C programming

Follow by Email
Facebook0
Facebook
Google+
https://codingsec.net/2016/12/formal-actual-parameters-c-programming/

 

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:

actuval-formal-params

In the above example, x and y are known as actual parameters and a and bare known as formal parameters. In the above code, we can see that the return type of the function add is void. This is a keyword in C. The voidkeyword is a datatype. If the function does not return any value, we specify the data type void. Generally void means nothing / no value.

Note: The formal parameters and actual parameters can have the same names i.e., if the actual parameters are x and y, then the formal parameters can also be x and y. But, it is recommended to use different names for actual and formal parameters.

 

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.

 

Predefined / Library Functions

A function is said to be a predefined function or library function, if they are already declared and defined by another developer. These predefined functions will be available in the library header files. So, if we want to use a predefined function, we have to include the respective header file in our program. For example, if we want to use printf function in our program, we have to include the stdio.h header file, as the function printf has been declared inside it.

 

Take your time to comment on this article.

Follow by Email
Facebook0
Facebook
Google+
https://codingsec.net/2016/12/formal-actual-parameters-c-programming/

2 Comments

  1. Ashok Pandey 2017-10-31 Reply
  2. Md arif 2018-01-31 Reply

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