type FunctionName(type parameter1, type parameter2, ...) /* function type is the type returned by it */
{
... ;
return value;
}
FunctionName(parameter); /* invokation */
- allows reusing of code
- note that variables scope is only within the function block
float CelciusFromFahrenheit(float tempF)
{
float tempC = (tempF - 32.0) * 5.0 / 9.0;
return tempC;
}
float tempC = CelciusFromFahrenheit(tempF);
main is the most important function, which is the entry point of a program
- the return value is the exit code
void Swap (int *a, int *b) /* accepts pointers */
{
int tmp = *a;
*a = *b;
*b = tmp;
}
int a = 10; int b = 20;
Swap(&a, &b); /* passing references */
printf(a, b)
- note that to the pointer references should be passed if the variable value needs to be changed outside the function