Function Calling in C Programming (Complete Guide with Examples)


This tutorial explains how to call functions in C. It covers syntax, examples, and the flow of execution, helping beginners understand how functions are used to make code modular, reusable, and organized.

1. What is Function Calling

Function calling is the process of executing a function from another function (usually main()).

When a function is called:

  1. Program control jumps to the function
  2. Executes the code inside the function
  3. Returns to the calling point

2. Syntax


return_value = function_name(arguments);
  1. function_name – Name of the function
  2. arguments – Values passed to the function (optional)
  3. return_value – Variable to store the result (if return type is not void)

3. Example: Calling a Function with Return Value


#include <stdio.h>

// Function declaration
int add(int a, int b);

int main() {
int num1, num2, sum;

printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);

// Function call
sum = add(num1, num2);

printf("Sum = %d\n", sum);
return 0;
}

// Function definition
int add(int a, int b) {
return a + b;
}

Sample Output:


Enter two numbers: 10 20
Sum = 30

4. Function Call Without Return Value

If the function does not return any value, use void as return type.


#include <stdio.h>

void greet() {
printf("Hello, Welcome to C Programming!\n");
}

int main() {
// Function call
greet();
return 0;
}

Output:


Hello, Welcome to C Programming!

5. Function Call with Arguments

You can pass values to a function using arguments.


#include <stdio.h>

void displayMessage(char name[]) {
printf("Hello, %s!\n", name);
}

int main() {
char username[20];
printf("Enter your name: ");
scanf("%s", username);

// Function call with argument
displayMessage(username);
return 0;
}

Sample Output:


Enter your name: Muni
Hello, Muni!

6. Key Points to Remember

  1. Functions must be declared before calling (or use prototypes)
  2. Arguments can be passed by value or reference (call by value/reference)
  3. Functions help modularize code and avoid repetition
  4. void functions do not return values, but can perform actions