This shows you the differences between two versions of the page.
c:stdlib.h:labs [2013/01/22 22:02] |
c:stdlib.h:labs [2024/02/16 01:04] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ====== labs ====== | ||
+ | |||
+ | <code c> | ||
+ | #include <stdlib.h> | ||
+ | long int labs(long int x); | ||
+ | </code> | ||
+ | |||
+ | computes the absolute value of a long integer\\ | ||
+ | \\ | ||
+ | returns the absolute value of a number\\ | ||
+ | the case of a negative number the sign is reversed, a positive number is returned unchanged.\\ | ||
+ | labs is functionally equivalent to abs (), but uses the data type long int\\ | ||
+ | |||
+ | ===== C Sourcecode Example ===== | ||
+ | <code c> | ||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | /* for printf */ | ||
+ | #include <stdlib.h> | ||
+ | |||
+ | int main( void ) | ||
+ | { | ||
+ | long int i = -42; | ||
+ | printf("labs from i = %li\n", labs(i)); | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ==== output with abort: ==== | ||
+ | user@host:~/code-reference.com# ./labs | ||
+ | labs from i = 42 | ||
+ | |||