The following example defines the function absolute with the return type double. Because this is a non-integer return type, absolute is declared prior to the function call.
#include <stdio.h>
double absolute(double);
int main(void)
{
double f = -3.0;
printf("absolute number = %lf\n", absolute(f));
}
double absolute(double number)
{
if (number < 0.0)
number = -number;
return number;
}
The following example defines the function absolute with the return type void. Within the function main, absolute is declared with the return type void.
#include <stdio.h>
int main(void)
{
void absolute(float);
float f = -8.7;
absolute(f);
}
void absolute(float number)
{
if (number < 0.0)
number = -number;
printf("absolute number = %f\n", number);
}
![]()
main()
Function
Function
Declarations
Function
Definitions
Examples of Function
Calls
Example of the
main() Function
Examples of Function
Definitions