C examples for Function:Function Definition
A function can return a value.
The following function returns an int value.
int getSum(int a, int b) { return a + b; }
Return statement exits the function and return the specified value to the caller.
#include <stdio.h> int getSum(int a, int b) { return a + b;/*from w ww .j a v a 2s .c om*/ } int main(void) { printf("%d", getSum(5, 10)); /* "15" */ }
The return statement can be used in a void function to exit the function.
void dummy(void) { return; }
return statement for main is optional.
int main(void) { return 0; /* optional */ }