Open In App

Function Arguments in Programming

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

Function Arguments are values or variables passed into a function when it is called. The arguments to a function play a significant role as they provide the necessary input for the function to perform its intended task. In this article, we will discuss what are Function Arguments in Programming across various programming languages.

What are Function Arguments?

Function Arguments are the input values passed to a function when it is called so that the function can use them while performing its task. The number of arguments that can be passed into a function is determined by the number of parameters in the function definition. Below is the syntax for Function Arguments:

function_name(arg1, arg2, ...), where arg1 and arg2 are arguments passed while calling the function.

Function Arguments in C:

Here is the implementation of the Function Arguments 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 4 and 5
    printSum(4, 5);
    return 0;
}

Output
9

Function Arguments in C++:

Here is the implementation of the Function Arguments 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 4 and 5
    printSum(4, 5);
    return 0;
}

Output
9

Function Arguments in Java:

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

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

import java.io.*;

class GFG {
    // 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 4 and 5
        printSum(4, 5);
    }
}

Output
9

Function Arguments in Python:

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

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

# Function call with arguments 4 and 5
printSum(4, 5)

Output
9

Function Arguments in C#:

Here is the implementation of the Function Arguments 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 4 and 5
        PrintSum(4, 5);
    }
}

Output
9

Function Arguments in Javascript:

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

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

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

Output
9

Conclusion:

In conclusion, function arguments are the values or variables that are passed into a function when it is called. They allow functions to perform tasks with specific inputs, making code reusable and flexible. Arguments can be variables, constants, or expressions, and they are used to customize the behavior of a function without needing to rewrite the function itself.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads