learnprogramming123

LEARN PROGRAMMING 123
your resources to programming and free tutition



Navigation

 
C
 
C++ soon here!
VB - soon here!

Search

 

 

Next Back

 

<limits.h>        -        Sizes of integral types

This library supplies machine-dependant macros that define the range of integer and character types.

jump to : example of <limits.h>

1 CHAR_BIT 8 number of bits in char
2 CHAR_MIN (-128) minimum if signed char, otherwise (0)
3 CHAR_MAX 127 maximum if signed char, otherwise (255)
4 MB_LEN_MAX 1 multiple byte lenght - maximum 1 byte
5 SCHAR_MAX 127 maximum signed char
6 SCHAR_MIN (-128) minimum signed char
7 UCHAR_MAX 255 maximum unsigned char
8 SHRT_MAX 32767 maximum short integer
9 SHRT_MIN -32767-1 minimum short integer
10 USRT_MAX 65535U maximum unsigned short integer
11 INT_MAX 32767 maximum integer
12 INT_MIN -32767-1 minimum integer
13 UNIT_MAX 0XFFFFU maximum unsigned integer
14 LONG_MAX 2147483647L maximum long integer
15 LONG_MIN (-2147483647L-1) mimimum long integer
16 ULONG_MAX 4294967295UL maximum unsigned long integer
       

Example:

This example will print the maximum and minimum value of the data type specifier int. Note that this can depend on the OS and compiler being used.

#include <stdio.h>
#include <limits.h>

int main(void)
{
    printf("The maximum value of INT can be %d\n", INT_MAX);

    printf("The minimum value of INT can be %d\n", INT_MIN);

    return 0;
}

The reason why these values can be different than the ones shown in the table above, are due mainly to the OS being used. When these limits were set back in the 70's, most people didn't predict that OS's would ever be as complex as they are now (modern OS's are 32-bit and even 64-bit).

These values were designed for the 16-bit operating system hence maxium range for int was assumed to be 2^16 (2 to the power of 16). 2^16 == (256*256) divided by 2 (for negative and positive ) and -1 for the positive range (0 is considered positive) gives an answer of 32767 - the MAX_INT. Since modern OS's are 32 bit, the range is now 2^32 not 2^16 - the range increases to 4294967295 - divide by 2 and substract 1 - and the maximum value of int becomes 2147483647 (the value printed out if you are using a modern version windows or linux or equivalent).

go to <locale.h>        back to top        back to main


 






1