C Standard Libraries C++

abs()

Declaration

int abs(int);

Description

Returns the absolute value of an int.

Related Functions

long labs(long lNumber);

* Note: Since C does not allow function overloading, these other versions of this function exist.

Example

#include <iostream>
#include <cstdlib>

int main() {
    using namespace std;

    cout << abs(17) << endl;
    cout << abs(-17) << endl;

    return 0;
}

Output

abs() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.