Function Arguments in Programming
Last Updated :
28 Mar, 2024
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;
}
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;
}
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);
}
}
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)
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);
}
}
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);
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.
Similar Reads
Function Arguments in R Programming Arguments are the parameters provided to a function to perform operations in a programming language. In R programming, we can use as many arguments as we want and are separated by a comma. There is no limit on the number of arguments in a function in R. In this article, we'll discuss different ways
4 min read
Functions in Programming Functions in programming are modular units of code designed to perform specific tasks. They encapsulate a set of instructions, allowing for code reuse and organization. In this article, we will discuss about basics of function, its importance different types of functions, etc.Functions in Programmin
14 min read
Function Calling in Programming Function Calling in programming refers to the process of invoking or executing a function within a program. Functions are blocks of code that perform a specific task, and they allow programmers to organize their code into reusable units, making it easier to manage and maintain. Table of Content What
4 min read
Functions in R Programming A function accepts input arguments and produces the output by executing valid R commands that are inside the function. Functions are useful when we want to perform a certain task multiple times.In R Programming Language when we are creating a function the function name and the file in which we are c
5 min read
Function Parameters in Programming 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
3 min read
Types of Functions in R Programming A function is a set of statements orchestrated together to perform a specific operation. A function is an object so the interpreter is able to pass control to the function, along with arguments that may be necessary for the function to accomplish the actions. The function in turn performs the task a
6 min read