Open In App

Function Parameters in Programming

Last Updated : 27 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Function Parameters are used to declare the input values that a function expects. The parameters of a function play a significant role while defining the function so that whenever we call the function, we ensure that necessary arguments are passed to the function. In this article, we will dive deep into Function Parameters in Programming across various programming languages.

What are Function Parameters?

Function Parameters are variables that are specified within the parentheses of a function definition. They represent the data that a function expects to receive when it is called. Parameters allow you to pass values into a function so that the function can perform its task using those values. Below is the syntax for Function Parameters:

return_type function_name(param1, param2), where param1 and param2 are function paramters.

Function Parameters in C:

Here is the implementation of the Function Parameter in C language:

C
#include <stdio.h>

// Function declaration with parameters
void printSum(int X, int Y) { printf("%d\n", (X + Y)); }

int main()
{
    // Function call with arguments
    printSum(4, 5);
    return 0;
}

Output
9

Function Parameters in C++:

Here is the implementation of the Function Parameter in C++ language:

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

// Function declaration with parameters
void printSum(int X, int Y) { cout << (X + Y) << endl; }

int main()
{
    // Function call with arguments
    printSum(4, 5);
    return 0;
}

Output
9

Function Parameters in Java:

Here is the implementation of the Function Parameter in java language:

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

import java.io.*;

public class Main {
    // Method definition with parameters
    static void printSum(int X, int Y)
    {
        System.out.println(X + Y);
    }

    public static void main(String[] args)
    {
        // Method call with arguments
        printSum(4, 5);
    }
}

Output
9

Function Parameters in Python:

Here is the implementation of the Function Parameter in python language:

Python3
# Function definition with parameters
def print_sum(X, Y):
    print(X + Y)

# Function call with arguments
print_sum(4, 5)

Output
9

Function Parameters in C#:

Here is the implementation of the Function Parameter in C#language:

C#
using System;

public class GFG
{
    // Method declaration with parameters
    static void PrintSum(int X, int Y)
    {
        Console.WriteLine(X + Y);
    }

    static void Main(string[] args)
    {
        // Method call with arguments
        PrintSum(4, 5);
    }
}

Output
9

Function Parameters in Javascript:

Here is the implementation of the Function Parameter in javascript language:

JavaScript
// Function definition with parameters
function printSum(X, Y) {
    console.log(X + Y);
}

// Function call with arguments
printSum(4, 5);

Output
9

Conclusion:

In conclusion, function parameters are variables that are specified in a function’s definition and serve as placeholders for values that are passed into the function when it is called. These parameters define the type and number of arguments that the function expects to receive.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads