C++ abs() Absolute Value with Examples

In C++, abs() function returns the absolute value of the given argument. By using abs function you can return absolute value for an int, float, double, long etc. data types in C++.

Basic Syntax

Following is the basic syntax for abs() function in C++:

int abs(int number)
double abs(double number)
float abs(float number)

And the parameters are:

numberint, float, double, short, long or byte number.

Return Value

abs() function returns absolute value of the given number.

  • For an integer value, it will return an integer
  • For float value, it will return a float and so on.


The output for the above program is as given below:

Integer num1 = 8
Float num2 = 90.0
Double num3 = 100.01
Long num4 = 20345676
Short num5 = 98
Byte num6 = 5


Please enter your comment!
Please enter your name here