First of all, you need #include <math.h> to use the abs function correctly.
Secondly, if the only thing you want to achieve is to print the absolute value INT_MIN defined in limits.h , you can simply print it as an unsigned integer or as a long long integer , for example:
printf( "abs(INT_MIN): %u\n", abs( INT_MIN ) ); // %u for unsigned int printf( "abs(INT_MIN): %lld\n", abs( INT_MIN ) ); // %lld for long long int
Since you want to have an absolute value that will definitely be unsigned, this should be ok.
If you do not want to include math.h , you can do it yourself:
// ternary implementation of the function abs printf( "abs(INT_MIN): %u\n", ( INT_MIN > 0 ) ? INT_MIN : -INT_MIN );
If you want to use it for other purposes, you can store the abs( INT_MIN ) value abs( INT_MIN ) in unsigned int or long long int variables.
Thoapplesin
source share