Function Arguments: Actual Argument And Formal Argument in C Language

Hello friends, in today’s article we are going to talking about Function Arguments or Function Parameter.

Today we will learn in detail about what are Arguments? how many types of Arguments in C Language? And What is Actual Argument and What is Formal Argument

Earlier we had known what is function and how to use function. If you have not read that article, then definitely read it once because to know about function argument well It is important to know about what is function

So now let’s understand what is Argument? or What is Parameter

Actual Arguments and Formal Arguments in C Language
Actual Arguments and Formal Arguments in C Language

What is Argument?

Whenever we create a function in C language, then while defining or declaring that function, we write something in its parenthesis, it is called Arguments or Parameters.

While defining or declaring a function, in the parenthesis of the function, we also write its data types along with the variable name.

By the way, writing or not writing anything in parenthesis depends on the behavior of that Function.

Like if there is a function which needs some number or value to perform its function, then we make a variable in its parenthesis by the variable declaration so that the function can put that value in these variables.

Example -:

//Here “ int var1, int var2 ” is a Function argument list
sum( int var1, int var2 )
{
  statements;
  statements;
   …
   …
   Body of Function
}

In this example, while defining the function, we have declared two variables var1 and var2 of int data type in its parenthesis so that when a value is passed while calling the function, then the function will be able to store those values ​​in these variables.

Argument or Parameter Type

In C language, it is divided into two parts on the basis of which argument is written in parenthesis at the time of function call and function declaration.

  1. Actual arguments
  2. Formal arguments

1. Actual arguments In C

When we write something in the parenthesis of the function while calling the function, then it is called Actual arguments or Actual parameters.

Example -:

  • int x = 2, y = 23;
  • func1(x, y);

In this example, x and y are the actual arguments written in the parenthesis of the function.

Actual arguments can contain constants, variables, expressions.

  • fun1(x, y); // Here actual arguments are variable
  • fun1(x + y, y + x); // Here actual arguments are expression
  • fun1(5, 60); // Here actual arguments are constant

2. Formal Arguments in C

When we write something in its parenthesis while defining the function, then it is called Formal arguments or Formal parameters.

All the values ​​that come in the formal arguments are copied from the actual arguments. Its scope is only up to that function and as soon as the function is destroyed, the variables created in it are also destroyed.

int area(int x)
{
    // write logic here
}

In this example int x is a formal argument whose scope is limited to that function only.

Important Point About Function Arguments in C Language

  • While calling the function, the order of number, data type in actual arguments should be the same order in formal arguments as well.
  • If the types of actual arguments and formal arguments do not match, then the compiler tries to convert the type of actual arguments to the type of formal arguments, if possible, otherwise, the formal argument gets a garbage value.
  • Whether a change in the formal arguments will affect the actual arguments depends on what type of value is being passed from the actual arguments to the formal argument.
  • If the value of a variable is being passed from Actual arguments to Formal arguments then the changes in Formal arguments will not affect the actual arguments and if the address of a variable is being passed from Actual arguments to Formal arguments then the changes occurring in Formal arguments The changes will affect the actual arguments.
  • When a value is passed by actual arguments, it is called Call by value and when an address is passed, it is called Call by address or Call by reference.

You can read about Call by value and Call by reference from here -: Call by Value and Call by Address in C

Example -:

// arguments call by value
#include <stdio.h>
int area(int l, int b) //Formal Arguments
{
    return( l*b );
 }
 
int main()
{
   int x, y, z;
   x = 5;
   y = 5;
   z = area(x,y); // call by value & actual arguments
   return 0;
}

Conclusion

Friends, I hope that after reading this article you know very well, what are Arguments? how many types of Arguments in C Language? And What is Actual Argument and What is Formal Argument

If you want a complete tutorial of C language, then see here C Language Tutorial. Here you will get all the topics of C Programming Tutorial step by step.

If you liked this post, then do not forget to share this post with your friends so that they can also get information about Function Arguments in C.

If you still have any questions or doubts related to Function Argument in C Language, then you must tell me, I will answer all your questions and you can contact us for more information.

Subscribe to this website newsletter to get information related to this new technology, Programming Language, Coding, C Language, C++Python Course, Java Tutorial.

Jeetu Sahu is A Web Developer | Computer Engineer | Passionate about Coding, Competitive Programming, and Blogging

Leave a Comment