Page 36
Write a program to determine the ranges of char
, short
, int
, and long
variables, both signed
and unsigned
, by printing appropriate values from standard
headers and by direct computation. Harder if you compute them: determine the ranges
of the various floating-point types.
#include <limits.h>
#include <stdio.h>
int main()
{
printf("--- From limits.h ---\n");
printf("char: %d:%d\n", CHAR_MIN, CHAR_MAX);
printf("short: %d:%d\n", SHRT_MIN, SHRT_MAX);
printf("int: %d:%d\n", INT_MIN, INT_MAX);
printf("long: %ld:%ld\n", LONG_MIN, LONG_MAX);
printf("unsigned char: 0:%u\n", UCHAR_MAX);
printf("unsigned short: 0:%u\n", USHRT_MAX);
printf("unsigned int: 0:%u\n", UINT_MAX);
printf("unsigned long: 0:%lu\n", ULONG_MAX);
/* The book also suggests that you should find these by 'direct computation'.
* I have no idea how to do that with the current info provided by the book,
* and am hesitant to go off on a tangent figuring this out from online resources. */
}