Facebook Page Twitter Page LinkedIn Page
× C Standard Library


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

Syntax

long int labs (long int n);

Parameters

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

Return Value

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

Example:

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

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

The output of the above code will be:

labs(10) = 10
labs(-10) = 10
labs(50) = 50
labs(-50) = 50

❮ C <stdlib.h> Library