INTEGERS

Minimal ANSI Limits ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– min const minimum value data type maximum value #bytes ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– short int -128 <= short int <= +127 1 int -32,768 <= int <= +32,767 2 long int -2,147,483,648 <= long int <= +2,147,483,647 4 –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

min const minimum value data type maximum value #bytes ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– unsigned short int 0 <= unsigned short int <= +255 1 unsigned int 0 <= unsigned int <= +65,535 2 unsigned long int 0 <= unsigned long int <= +4,294,967,295 4 –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

Integer Format Specifiers –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– Data Type Format Specifier Right Justify 8 Characters Left Justify 8 Characters –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– short int %h or %hi %8h or %8hi %–8h or %–8hi int %d or %i %8d or %8i %–8d or %–8i long int %ld or %li %8ld or %8li %–8ld or %–8li

unsigned short int%hu %8hu %–8hu unsigned int %u %8u %–8u unsigned long int %lu %8lu %–8lu ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

%5d or %5i used to right justify (5 character) int %7ld or %7li used to right justify (7 character) long int %3h or %3hi used to right justify (3 character) short int %12u used to right justify (12 character) unsigned int %8lu used to right justify (8 character) long unsigned int %4hu used to right justify (4 character) short unsigned int %-5d or %-5i used to left justify (5 character) int %-7ld or %-7li used to left justify (7 character) long int %-3h or %-3hi used to left justify (3 character) short int

%o or %O used for Octal Notation %x or %X used for Hexadecimal Notation

The format control string may also include any of the following escape sequences: (note that the escape sequences begin with the \ and alter the flow of printing for special events)

\n (newline) to move the cursor to the first position of the next line \r (return) to move the cursor to the first position of the line \f (formfeed) to move the cursor to the first position of the first line [2]

of the next page (often clears console screen) \t (horiz tab) to move the cursor to the next horizontal tab position of the current line \b (backspace) to move the cursor one position to the left \a (alert) to produce a visible or audible alert

\\ to print the backslash \" to print the double quote \' to print the single quote \? to print the question mark \07 to ring the bell

PROGRAM IntOut.c

# include # define MAX 3333 # define MAX 3

main() { int No;

No = 2371; printf ("Example 1 : *%d*\n",2371); printf ("Example 2 : *%2d*\n",MAX); printf ("Example 3 : *%4d*\n",2371); printf ("Example 4 : *%7d*\n",2371); printf ("Example 5 : *%-7d*\n",No); printf ("Example 6 : *%-2d*\n",2371); printf ("Example 7 : *%d%d%d*\n",1,2,3); printf ("Example 8 : *%d%d%d*\n",1,-2,3); printf ("Example 9 : *%d %d %d*\n",1,2,3); printf ("Example 10: *%2d %2d*\n",123,2371); printf ("Each int declared allocates %lu bytes\n",sizeof (int)); printf ("The amount of space allocated for variable No is %lu bytes\n", sizeof (No)); printf ("The amount of space allocated constant MAX is %lu bytes\n",sizeof (MAX)); printf ("The amount of space allocated constant MIN is %lu bytes\n",sizeof (MIN)); return (0); }

Output from program IntOut.c is as follows:

Example 1 : *2371* Example 2 : *3333* Example 3 : *2371* Example 4 : * 2371* Example 5 : *2371 * Example 6 : *2371* Example 7 : *123* Example 8 : *1-23* Example 9 : *1 2 3* Example 10: *123 2371* [3]

Each int declared allocates 2 bytes The amount of space allocated for variable No is 2 bytes The amount of space allocated constant MAX is 2 bytes The amount of space allocated constant MIN is 2 bytes