Skip to main content

Calling a Function in C

Calling a Function

  • "Calling a function" means executing a function. It is an important part of the C programming. It can be refered as an instruction that invokes or executes a function defined in the program.

  • When we declare a function it is not executed immediately rather gets saved for later use in the program.

  • When a function is "called", the program control is transferred to the function and the function code is executed. Once the function has completed its task, control is returned to the part of the program that called the function.

Here's an example of calling a function in C:

#include <stdio.h>

void print_hello()
{
printf("Hello!\n");
}

int main()
{
print_hello(); //Function is called
return 0;
}
Output:

Explanation

The function print_hello is defined to print the message "Hello!". In the main function, the print_hello function is called. When the program is executed, it will print the message "Hello!".

info

There are several terms used in C to describe "calling a function", and they all mean the same thing, including:

  • Calling a function
  • Invoking a function
  • Executing a function
  • Activating a function
  • Triggering a function
  • Running a function
  • Starting a function
  • Dispatching a function