Syntax
#include <stdlib.h> int abs(int n);Description
abs returns the absolute value of an integer argument n.
There is no error return value. The result is undefined when the absolute value of the argument cannot be represented as an integer. The value of the minimum allowable integer is defined by -INT_MAX in the <limits.h> include file.
This example calculates the absolute value of an integer x and assigns it to y.
#include <stdio.h> #include <stdlib.h> int main(void) { int x = -4, y; y = abs(x); /* y = 4 */ printf("abs( %d ) = %d\n", x, y); return 0; /**************************************************************************** The output should be: abs( -4 ) = 4 ****************************************************************************/ }Related Information