Function calling lets you run a set of instructions saved in one place. It helps you reuse code and keep your program organized.
Function calling
function_name(arguments);
The function_name is the name of the function you want to run.
arguments are the values you give to the function to work with. If no values are needed, leave empty parentheses ().
printHello that takes no arguments.printHello();
sum with two numbers, 5 and 10.sum(5, 10);
multiply with 3 and 4, and saves the returned value in result.int result = multiply(3, 4);
This program shows two functions: greet prints a message, and add returns the sum of two numbers. In main, we call both functions and print the results.
#include <stdio.h> // Function that prints a greeting void greet() { printf("Hello, friend!\n"); } // Function that adds two numbers and returns the sum int add(int a, int b) { return a + b; } int main() { greet(); // Call greet function int sum = add(7, 8); // Call add function with 7 and 8 printf("Sum is %d\n", sum); return 0; }
Always declare or define a function before calling it, so the compiler knows about it.
Functions can return values or just perform actions without returning anything.
Arguments must match the function's expected types and order.
Function calling runs code saved in a function to reuse and organize your program.
You call a function by writing its name followed by parentheses and any needed values.
Functions help break big tasks into smaller, manageable parts.