I have written a simple program fabs.c
to display the absolute value of a floating point number.
#include <stdio.h>
#include <math.h>
int main(void)
{
float f;
printf("Enter a floating-point number: ");
scanf("%f", &f);
printf("Its absolute value is %f.\n", fabs(f));
return 0;
}
fabs() function requires including the math.h
header file, but I compiled successfully without -lm
option.
gcc fabs.c -o fabs
Even man fabs
says link with -lm
. But I don't know why I can compile it successfully without -lm
.