C++ Standard Library C++ STL Library

C++ <cstdlib> - llabs() Function



The C++ <cstdlib> llabs() 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 long int llabs (long long int 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 <cstdlib> llabs() function.

#include <iostream>
#include <cstdlib>
using namespace std;
 
int main (){
  cout<<"llabs(10) = "<<llabs(10)<<"\n";
  cout<<"llabs(-10) = "<<llabs(-10)<<"\n";
  cout<<"llabs(50) = "<<llabs(-50)<<"\n";
  cout<<"llabs(-50) = "<<llabs(50)<<"\n";  
  return 0;
}

The output of the above code will be:

llabs(10) = 10
llabs(-10) = 10
llabs(50) = 50
llabs(-50) = 50

❮ C++ <cstdlib> Library