C examples for Function:Function Definition
The following code defines a function with two parameter.
void sum(int a, int b) { int sum = a + b; printf("%d", sum); }
In this example, the function accepts two integer arguments and displays their sum.
#include <stdio.h> void sum(int a, int b) { int sum = a + b; printf("%d", sum); } int main(void) { sum(2, 3); /* "5" */ }
To ensure that no arguments are passed to a parameterless function, include void in the parameter list.
/* Accepts no arguments */ void foo(void) {} /* Accepts an unknown number of arguments */ void bar() {}