abs()

The abs() function returns the absolute value of the argument.

Syntax

abs(n)

Example 1

Use abs() to return the absolute value of -6.5:

#include <iostream>
#include <cmath>
int main() {
std::cout << std::abs(-6.5) << "\n";
// Output: 6.5
}
Looking to contribute?

Learn C++ on Codecademy