Easy Tutorial
❮ C Function Strncmp C Examples Alphabet ❯

C Library Function - abs()

C Standard Library - <stdlib.h>

Description

The C library function int abs(int x) returns the absolute value of x.

Declaration

Here is the declaration for the abs() function.

int abs(int x)

Parameters

Return Value

This function returns the absolute value of x.

Example

The following example demonstrates the use of the abs() function.

#include <stdio.h>
#include <stdlib.h>

int main ()
{
   int a, b;

   a = abs(5);
   printf("Value of a = %d\n", a);

   b = abs(-10);
   printf("Value of b = %d\n", b);

   return(0);
}

Let's compile and run the above program, which will produce the following result:

Value of a = 5
Value of b = 10

C Standard Library - <stdlib.h>

❮ C Function Strncmp C Examples Alphabet ❯