Open In App

Function Calling in Programming

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

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;
}

Output
5 + 10 = 15

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;
}

Output
5 + 10 = 15

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);
    }
}

Output
5 + 10 = 15

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}")

Output
5 + 10 = 15

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}");
    }
}

Output
5 + 10 = 15

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);

Output
5 + 10 = 15

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

Function Overloading vs Function Overriding in Programming
Function Overloading allows multiple functions with the same name but different parameters, enabling the same function name to perform different tasks based on input parameters. On the other hand, Function Overriding is a feature that allows a subclass to provide a specific implementation of a method that is already provided by its parent class, en
3 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 into Function Parameters in Programming across var
3 min read
Function Arguments in Programming
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. Table of Content
3 min read
Function Overloading in Programming
Function Overloading in programming allows multiple functions to have the same name but with different parameters. It lets a function perform different tasks based on the input parameters. This increases the flexibility and readability of the code. Languages like C++, Java, and C# have­ function overloading. A programmer can provide diffe­rent impl
11 min read
Which Programming Language to Choose?
One of the most annoying question today is which programming language should be chosen for the sake of education/career or anything. Answer for this question to many programmers ends up with C or C++, or mostly Java but why C? why C++? Why Java?. Today many software exists, to solve a problem but also to interfere with another software. nowadays in
4 min read
Hello World Program : First program while learning Programming
In this article, I'll show you how to create your first Hello World computer program in various languages. Along with the program, comments are provided to help you better understand the terms and keywords used in theLearning program. Programming can be simplified as follows: Write the program in a text editor and save it with the correct extension
6 min read
What are Objects in Programming?
In object-oriented programming (OOP), objects are the basic entities that actually exists in the memory. Each object is based on a blueprint of attributes and behaviours (variables and functions) defined as Class. The basic purpose of a Class is to identify the common attributes and behaviours and group them as an entity that can be reused again an
2 min read
If-Then-___ Trio in Programming
Learning to code is a bit like discovering magic spells, and one trio of spells you'll encounter often is called "If-Then-___." These spells help your code make decisions like a wizard choosing the right spell for a particular situation. Table of Content If-Then-ElseIf-Then-TernaryIf-Then-ThrowIf-Then-Async/AwaitWhen to use each If-Then-___ Trio in
2 min read
Complete Reference for Bitwise Operators in Programming/Coding
There exists no programming language that doesn't use Bit Manipulations. Bit manipulation is all about these bitwise operations. They improve the efficiency of programs by being primitive, fast actions. There are different bitwise operations used in bit manipulation. These Bitwise Operators operate on the individual bits of the bit patterns. Bit op
13 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?Code in Programming Language:Types of CodeDifferent
10 min read
Article Tags :