Function Calling in Programming
Last Updated :
26 Mar, 2024
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.
What is Function Calling?
Function Calling involves specifying the function's name followed by parentheses(). If the function requires input values, known as parameters, then they are passed inside the parentheses as arguments. When the function is called, the program execution jumps to the function's code block, executes it, and then returns control to the point in the program where the function was called.
Syntax:
Below is the most common syntax to call a function:
function_name(argument_1, argument_2, argument_3, ...)
If a function returns some value and we need to store the value in a variable, then we can write it as:
variable_name = function_name(argument_1, argument_2, argument_3, ...)
Function Calling in C:
Here are the implementation of Function Calling in C language:
C
#include <stdio.h>
// sum function which takes two parameters and return their
// sum
int sum(int a, int b) { return a + b; }
int main()
{
int x = 5, y = 10;
// Calling the function sum with x and y as arguments
int s = sum(x, y);
printf("%d + %d = %d", x, y, s);
return 0;
}
Function Calling in C++:
Here are the implementation of Function Calling in C++ language:
C++
#include <iostream>
using namespace std;
// sum function which takes two parameters and returns their
// sum
int sum(int a, int b) { return a + b; }
int main()
{
int x = 5, y = 10;
// Calling the function sum with x and y as arguments
int s = sum(x, y);
cout << x << " + " << y << " = " << s;
return 0;
}
Function Calling in Java:
Here are the implementation of Function Calling in java language:
Java
/*package whatever //do not write package name here */
import java.io.*;
class GFG {
// sum function which takes two parameters and returns
// their sum
public static int sum(int a, int b) { return a + b; }
public static void main(String[] args)
{
int x = 5, y = 10;
// Calling the function sum with x and y as
// arguments
int s = sum(x, y);
System.out.println(x + " + " + y + " = " + s);
}
}
Function Calling in Python:
Here are the implementation of Function Calling in python language:
Python3
# sum function which takes two parameters and returns their sum
def sum(a, b):
return a + b
x, y = 5, 10
# Calling the function sum with x and y as arguments
s = sum(x, y)
print(f"{x} + {y} = {s}")
Function Calling in C#:
Here are the implementation of Function Calling in C# language:
C#
using System;
public class GFG {
// sum function which takes two parameters and returns
// their sum
static int Sum(int a, int b) { return a + b; }
static void Main()
{
int x = 5, y = 10;
// Calling the function sum with x and y as
// arguments
int s = Sum(x, y);
Console.WriteLine($"{x} + {y} = {s}");
}
}
Function Calling in JavaScript:
Here are the implementation of Function Calling in javascript language:
JavaScript
// sum function which takes two parameters and returns their sum
function sum(a, b) {
return a + b;
}
let x = 5, y = 10;
// Calling the function sum with x and y as arguments
let s = sum(x, y);
console.log(x + " + " + y + " = " + s);
Conclusion:
In programming, function calling is when you ask a program to run a specific block of code that you've defined elsewhere. It's like giving a command to execute a particular task, and it helps make your code organized, reusable, and easier to understand.
Similar Reads
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
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 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
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
Function Pointer in C++ Prerequisites: Pointers in C++Function in C++ Pointers are symbolic representations of addresses. They enable programs to simulate call-by-reference as well as to create and manipulate dynamic data structures. Iterating over elements in arrays or other data structures is one of the main use of point
4 min read
What is a Code in Programming? In programming, "code" refers to a set of instructions or commands written in a programming language that a computer can understand and execute. In this article, we will learn about the basics of Code, types of Codes and difference between Code, Program, Script, etc. Table of Content What is Code?Co
10 min read
Build a function in R Functions are key elements in R Programming Language allowing code to be packaged into reusable blocks. They simplify tasks by making code more modular, readable, and maintainable. So whether conducting data analysis, creating visualizations, or developing complex statistical models, understanding h
6 min read
Graphing Function Graphing Function is the process of illustrating the graph (the curve) for the function that corresponds to it. Plotting simple functions like linear, quadratic, cubic, et al. examples doesnât pose a challenge; depicting functions of a more complex nature like rational, logarithmic, and others requi
13 min read
Mapping Functions in LISP In this article, we will discuss mapping functions in lisp. Mapping functions are applied on the list data structure for combining one or more lists of elements. By using this we can perform mathematical operations and can join the elements. The main advantage of this function is that we can combine
2 min read