C abs — absolute value

In C, abs returns the magnitude of a number. For example, the absolute value of −6 is 6, and the absolute value of 0 is 0.

A simple example

abs

  1. Start with −3
  2. Do this Measure distance from zero
  3. Result 3
From −3, three unit steps reach zero. The magnitude is 3.
lesson.c
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    printf("%.15g\n", (double) (abs(-3)));
}
Output
3