C Standard Library

C <inttypes.h> - imaxabs() Function



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

Note: This function is equivalent to abs() function for intmax_t.

Syntax

intmax_t imaxabs (intmax_t x);  

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 example below shows the usage of <inttypes.h> imaxabs() function.

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

The output of the above code will be:

imaxabs(10) = 10
imaxabs(-10) = 10
imaxabs(50) = 50
imaxabs(-50) = 50

❮ C <inttypes.h> Library