Formal and Actual Parameters in Programming

In programming, parameters are variables or values passed to a function or method during its invocation. They enable the function to receive input data, perform operations, and optionally return a result.

What are Formal Parameters?

Formal parameters, also known as formal arguments, are placeholders defined in the function signature or declaration. They represent the data that the function expects to receive when called. Formal parameters serve as variables within the function’s scope and are used to perform operations on the input data.

Syntax of Formal parameters:

Below is the syntax for Formal parameters:

Syntax of Formal Parameters
// Here, 'name' is the formal parameter
function gfgFnc(name) {
    // Function body
}

What are Actual Parameters?

Actual parameters, also called actual arguments or arguments, are the values or expressions provided to a function or method when it is called. They correspond to the formal parameters in the function’s definition and supply the necessary input data for the function to execute. Actual parameters can be constants, variables, expressions, or even function calls.

Syntax of Actual parameters:

Below is the syntax for Actual parameters:

Syntax of Actual Parameters
function gfgFnc(name) {
    // Function body
}

// Actual Parameter
gfgFnc("Geek");

Formal and Actual parameters in C:

Below is the implementation of Formal and Actual Parameters in C:

C
#include <stdio.h>

// a and b are formal parameters
int sum_numbers(int a, int b) { return a + b; }

int main()
{
    // 3 and 5 are actual parameters
    int result = sum_numbers(3, 5);
    printf("Sum: %d\n", result);
    return 0;
}

Output
Sum: 8

Formal and Actual Parameters in C++:

Below is the implementation of Formal and Actual Parameters in C++:

C++
#include <iostream>
using namespace std;

// a and b are formal parameters
int sum_numbers(int a, int b) { return a + b; }

int main()
{
    // 3 and 5 are actual parameters
    int result = sum_numbers(3, 5);
    cout << "Sum: " << result << endl;
    return 0;
}

Output
Sum: 8

Formal and Actual Parameters in Java:

Below is the implementation of Formal and Actual Parameters in Java:

Java
/*package whatever //do not write package name here */

import java.io.*;

class GFG {
    // a and b are formal parameters
    static int sumNumbers(int a, int b) { return a + b; }

    public static void main(String[] args)
    {
        // 3 and 5 are actual parameters
        int result = sumNumbers(3, 5);
        System.out.println("Sum: " + result);
    }
}

Output
Sum: 8

Formal and Actual Parameters in Python:

Below is the implementation of Formal and Actual Parameters in Python:

Python
# a and b are formal parameters
def sum_numbers(a, b):
    return a + b

# 3 and 5 are actual parameters
result = sum_numbers(3, 5)
print("Sum:", result)

Output
Sum: 8

Formal and Actual Parameters in C#:

Below is the implementation of Formal and Actual Parameters in C#:

C#
using System;

class Program {
    // a and b are formal parameters
    static int SumNumbers(int a, int b) { return a + b; }

    static void Main(string[] args)
    {
        // 3 and 5 are actual parameters
        int result = SumNumbers(3, 5);
        Console.WriteLine("Sum: " + result);
    }
}

Output
Sum: 8

Formal and Actual Parameters in JavaScript:

Below is the implementation of Formal and Actual Parameters in JavaScript:

JavaScript
// a and b are formal parameters
function sumNumbers(a, b) {
    return a + b;
}

// 3 and 5 are actual parameters
let result = sumNumbers(3, 5);
console.log("Sum: " + result);

Output
Sum: 8