Format
#include <stdlib.h> int abs(int n);
Language Level: ANSI, POSIX, XPG4, Extension
abs returns the absolute value of an integer argument n.
Return Value
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.
Example
This example calculates the absolute value of an integer x and
assigns it to y.
#include <stdlib.h> #include <stdio.h>
int main(void)
{
int x = -4, y;
y = abs(x);
printf("The absolute value of x is %d.\n", y);
return 0;
/**********************************************
The output should be:
The absolute value of x is 4.
**********************************************/
}
![]()
_cabs -- Calculate Absolute Value of Complex
Number
fabs -- Calculate Floating-Point
Absolute Value
labs -- Calculate Absolute Value of Long
Integer
<limits.h>
<stdlib.h>