a shot of dev knowledge

Related tags

What is llabs() in C++?

llabs() is another type of abs() function in which both the type of input and output is long long int or long long. In other words, it can be considered as a long long int version of the abs() function.

The illustration below shows the C++ equivalent of the mathematical expression:

C++ representation of the mathematical expression

In order to use the llabs() function, we must include cstdlib in the program, as shown below:

#include <cstdlib>


long long llabs(long long x)
long long int llabs(long long int x)


This function takes in a single parameter of type long long or long long int.

Return value

llabs() returns the absolute value of long long or long long int sent as a parameter.


#include <iostream>
#include <cstdlib>
using namespace std;

int main() {
  long long int number_1 = -2394545329003567669LL;
  long long number_2 = -89187008890LL;

  cout << "llabs(" << number_1 << ") = |" << number_1 << "| = " << llabs(number_1);
  cout << endl;
  cout << "llabs(" << number_2 << ") = |" << number_2 << "| = " << llabs(number_2);
  return 0;

Related tags

View all Courses
Related Courses
Related Courses
View all Courses

Keep Exploring