Computes the absolute value of an integer.
#include <stdlib.h> int abs(int i);
i
Value from which to compute the absolute value.
abs() returns the absolute value of its argument. Note that the two's complement representation of the smallest negative number has no matching absolute integer representation.
#include <stdlib.h> #include <stdio.h> int main(void) { int i = -20; long int j = -48323; long long k = -9223372036854773307; printf("Absolute value of %d is %d.\n", i, abs(i)); printf("Absolute value of %ld is %ld.\n", j, labs(j)); printf("Absolute value of %lld is %lld.\n", k, llabs(k)); return 0; } Output: Absolute value of -20 is 20. Absolute value of -48323 is 48323. Absolute value of -9223372036854773307 is 9223372036854773307.