4.6 Integers

I l @ ve RuBoard

One variable type is integer. Integers (also known as whole numbers) have no fractional part or decimal point. Numbers such as 1, 87, and -222 are integers. The number 8.3 is not an integer because it contains a decimal point. The general form of an integer declaration is:

 int   name   ;   //   comment   

A calculator with an eight-digit display can only handle numbers between 99,999,999 and -99,999,999. If you try to add 1 to 99,999,999, you will get an overflow error. Computers have similar limits. The limits on integers are implementation- dependent, meaning they change from computer to computer.

Calculators use decimal digits (0-9). Computers use binary digits (0-1) called bits . Eight bits make a byte . The number of bits used to hold an integer varies from machine to machine. Numbers are converted from binary to decimal for printing.

On most machines integers are 32 bits (4 bytes), providing a range of 2,147,483,647 (2 31 - 1) to -2,147,483,648 (-2 31 ). Some systems now use newer processors such as the Intel Itanium, which have 64-bit integers, giving you a range of 9223372036854775807 (2 63 -1) to -9223372036854775807 (-2 63 ) If you are programming using an older MS-DOS compiler, only 16 bits (2 bytes) are used, so the range is 32,767 (2 15 -1) to -32,768 (-2 15 ).

Question 4-1: The following will work on a Unix machine but will fail on an old MS-DOS system.

 int zip;      // zip code for current address .........  zip = 92126; 

Why does this fail? What will be the result when this program is run on an MS-DOS system?

I l @ ve RuBoard


Practical C++ Programming
Practical C Programming, 3rd Edition
ISBN: 1565923065
EAN: 2147483647
Year: 2003
Pages: 364

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net