The decimal numeric system counts from minus infinity to infinity. This means that numbers are usually negative or positive, depending on their position from 0, which is considered as neutral. In some operations, the number considered will need to be only positive even if it is provided in a negative format. The absolute value of a number x is x if the number is (already) positive. If the number is negative, its absolute value is its positive equivalent. For example, the absolute value of 12 is 12, while the absolute value of –12 is 12.
To get the absolute value of a number, you can use one of the C/C++ abs() function. Its syntax is:
int abs(int x);
This function takes an integer as the argument and returns its absolute value equivalent. Here is an example: