C Programming • Arrays & Functions
C Programming / Formal and Actual arguments

Formal and Actual arguments

Notes 3 Arrays & Functions

Definition: Arguments are values or variables used to pass information to a function. In C, arguments used in the function definition are called formal parameters, while the values or variables supplied during the function call are called actual arguments.

Notes

Formal and Actual Arguments

Definition: Arguments are values or variables used to pass information to a function. In C, arguments used in the function definition are called formal parameters, while the values or variables supplied during the function call are called actual arguments.

💡 Example: In add(x, y), x and y used in the function call are actual arguments. In int add(int a, int b), a and b are formal parameters.

Formal Parameters

Definition: Formal parameters are variables written in the function definition that receive values from the function call.

💡 Example: In int add(int a, int b), a and b are formal parameters.
int add(int a, int b)
{
    return a + b;
}

Actual Arguments

Definition: Actual arguments are the values or variables supplied when a function is called.

💡 Example: In add(10, 20), 10 and 20 are actual arguments.
int result = add(10, 20);

Formal vs Actual Arguments

Formal Parameters Actual Arguments
Written in the function definition. Written in the function call.
Receive the values passed to the function. Provide values to the function.
Example: a, b Example: 10, 20
They are variables. They can be constants, variables or expressions.

How Arguments Are Matched

Definition: During a function call, actual arguments are matched with the corresponding formal parameters according to their position.

💡 Example: In add(10, 20), 10 is passed to a and 20 is passed to b.
int add(int a, int b)
{
    return a + b;
}

add(10, 20);

Order of Arguments

The order of actual arguments is important because each argument corresponds to the formal parameter in the same position.

💡 Example: subtract(10, 5) is different from subtract(5, 10) because the values are passed in a different order.

Number of Arguments

The number of supplied arguments should correspond to the parameters expected by the function call, subject to the function's declaration and language rules.

💡 Example: If a function is declared as int add(int a, int b), it expects two integer arguments, such as add(10, 20).

Arguments Can Be Variables

Actual arguments do not have to be fixed numbers. Variables can also be passed to a function.

💡 Example: add(x, y) passes the current values of x and y.

Arguments Can Be Expressions

An expression can also be supplied as an actual argument. The expression is evaluated and its resulting value is passed to the function.

💡 Example: In add(x + 5, y * 2), the two expressions are evaluated and their values are passed to the function.

Simple Example

#include <stdio.h>

int multiply(int a, int b)       // a and b are formal parameters
{
    return a * b;
}

int main()
{
    int x = 5;
    int y = 4;

    int result = multiply(x, y); // x and y are actual arguments

    printf("Result = %d
", result);

    return 0;
}

Output

Result = 20

Practical Example — Add Two Numbers Using Arguments

Problem Statement

Write a C program that accepts two integers and passes them to a user-defined function to calculate their sum.

Learning Outcomes

  • Understand formal parameters and actual arguments.
  • Pass variables to a user-defined function.
  • Observe how values are matched with function parameters.

Hint

Create an add() function with two formal parameters. Pass two variables from main() as actual arguments.

Theory

Formal parameters appear in the function definition and receive values from the corresponding actual arguments supplied during the function call.

Program

#include <stdio.h>

int add(int a, int b);             // a and b are formal parameters

int main()
{
    int x, y, result;

    printf("Enter two numbers: ");
    scanf("%d %d", &x, &y);

    result = add(x, y);            // x and y are actual arguments

    printf("Sum = %d
", result);

    return 0;
}

int add(int a, int b)
{
    return a + b;                  // calculate and return the sum
}

Expected Output

Enter two numbers: 10 25
Sum = 35

Note

Here, x and y are actual arguments in the function call, while a and b are formal parameters in the function definition.

Easy Way to Remember

🎯 Actual → Gives the value

Formal → Receives the value

Important Points for Exam

  • Formal parameters are written in the function definition.
  • Actual arguments are supplied in the function call.
  • Actual arguments provide values to formal parameters.
  • Arguments are matched according to their position.
  • Actual arguments may be constants, variables or expressions.
  • Formal parameters are local to the function in which they are defined.

Quick Revision

Term Remember Example
Formal Parameter Receives the value. a, b
Actual Argument Provides the value. 10, 20
Function Definition Contains formal parameters. add(int a, int b)
Function Call Contains actual arguments. add(10, 20)

Important Exam Questions

Short Answer Questions

  1. What are formal parameters?
  2. What are actual arguments?
  3. Where are formal parameters written?
  4. Where are actual arguments written?
  5. How are actual arguments matched with formal parameters?
  6. Can variables be used as actual arguments?
  7. Differentiate between formal parameters and actual arguments.

Long Answer Questions

  1. Explain formal parameters and actual arguments with suitable examples.
  2. Differentiate between formal and actual arguments in C.
  3. Write a C program to add two numbers using a function and explain its formal parameters and actual arguments.
🎥 Recommended Learning

Watch a beginner-friendly explanation of formal and actual arguments in C.

▶ Watch: Formal & Actual Arguments — Hindi

📝 Handwritten Notes

A short handwritten-style revision sheet for formal and actual arguments will be provided here.

🧠 Mind Map

Use the mind map for quick revision of function calls, formal parameters and actual arguments.