C abs() function

C abs() function - Calculate integer absolute value

The abs() function is used to compute the absolute value of an integer value.

Syntax abs() function

int abs(int x)

Parameters abs() function

Name Description Required /Optional
x Numeric value. Required

Return value from abs()

  • Absolute value of its integer operand.

Example: abs() function

The following example shows the usage of abs() function.

#include <stdlib.h>
#include <stdio.h>
int main(void)
    int x, y;
    x = -347;
    y = abs(x);
    printf("The absolute value of %d is %d\n", x, y);
    x = 456; 
    y = abs(x);
    printf("\nThe absolute value of %d is %d\n", x, y); 


The absolute value of -347 is 347

The absolute value of 456 is 456

C Programming Code Editor:

Previous C Programming: C qsort()
Next C Programming: C div()

Follow us on Facebook and Twitter for latest update.