C++ llabs()

The llabs() function in C++ returns the absolute value of a long long int data.

The llabs() function can be thought as the long long int version of abs().

It is defined in <cstdlib> header file.

[Mathematics] |x| = llabs(x) [C++ Programming]

llabs() prototype [As of C++ 11 standard]

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

The llabs() function takes a single argument of type long long or long long int and returns a value of same type.


llabs() Parameters

x: A long long or long long int data whose absolute value is returned.


llabs() Return value

The llabs() function returns the absolute value of x i.e. |x|.


Example: How llabs() function works in C++?

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

int main()
{
	long long x,y;
	x = -79182028361LL;
	y = 129301730192LL;

	cout << "llabs(" << x << ") = |" << x << "| = " << llabs(x) << endl;
	cout << "llabs(" << y << ") = |" << y << "| = " << llabs(y) << endl;
	
	return 0;
}

When you run the program, the output will be:

llabs(-79182028361) = |-79182028361| = 79182028361
llabs(129301730192) = |129301730192| = 129301730192
Did you find this article helpful?