C Standard Library

C <stdlib.h> - abs() Function

The C <stdlib.h> abs() function returns the absolute value (positive value) of the specified integral value. For example - absolute value of integral value x will be |x|.


int abs (int x);


x Specify an integral value whose absolute value need to be determined.

Return Value

Returns the absolute value (positive value) of integral argument.


The example below shows the usage of <stdlib.h> abs() function.

#include <stdio.h>
#include <stdlib.h>
int main (){
  printf("abs(10) = %d\n", abs(10));
  printf("abs(-10) = %d\n", abs(-10));
  printf("abs(50) = %d\n", abs(-50));
  printf("abs(-50) = %d\n", abs(50));  
  return 0;

The output of the above code will be:

abs(10) = 10
abs(-10) = 10
abs(50) = 50
abs(-50) = 50

❮ C <stdlib.h> Library