Actual and Formal arguments in C

Actual arguments

Arguments which are mentioned in the function call is known as the actual argument. For example:

here 12 and 23 are actual arguments.

Actual arguments can be constant, variables, expressions etc.

Formal Arguments

Arguments which are mentioned in the definition of the function is called formal arguments. Formal arguments are very similar to local variables inside the function. Just like local variables, formal arguments are destroyed when the function ends.

Here n is the formal argument.

Things to remember about actual and formal arguments.

  1. Order, number, and type of the actual arguments in the function call must match with formal arguments of the function.
  2. If there is type mismatch between actual and formal arguments then the compiler will try to convert the type of actual arguments to formal arguments if it is legal, Otherwise, a garbage value will be passed to the formal argument.
  3. Changes made in the formal argument do not affect the actual arguments.

The following program demonstrates this behaviour.

Here the value of variable x is 10 before the function func_1() is called, after func_1() is called, the value of x inside main() is still 10. The changes made inside the function func_1() doesn’t affect the value of x. This happens because when we pass values to the functions, a copy of the value is made and that copy is passed to the formal arguments. Hence Formal arguments work on a copy of the original value, not the original value itself, that’s why changes made inside func_1() is not reflected inside main(). This process is known as passing arguments using **Call by Value**, we will discuss this concept in more detail in upcoming chapters.

1 thought on “Actual and Formal arguments in C

Leave a Comment

%d bloggers like this: