go to previous page   go to home page   go to next page hear noise

Can data type short hold the value 1,023,004 ?


No. Data of type short can be only in the range -32,768 to +32,767.

More Bits for More Range

Larger ranges of numeric values require more bits. The different sizes for integer data enable you to pick an appropriate size for the data you are working with. Usually you should pick a data type that has a range much greater than the range of numbers you expect to deal with. If a program uses only a few dozen variables it will run just as fast and take up about as much main memory no matter what size is used for its variables.

Why do the small sized data types exist, then? Well, many real-world programs deal with massive amounts of data (billions of data items) and then using the smaller sizes may save significant amounts of space and time. But we will not use that much data in these notes. Usually you should use int or double for your numeric data.

When you write a program you do not have to know how to represent a number in bits. You can type the number just as you would on a typewriter. This is called a literal. The word "literal" means that a value is explicitly shown in the program.

For example, 125 literally represents the value one hundred twenty five. Integer literals in a program are written as in a book, except there are no commas:


All of the above examples are 32 bit int literals.

A 64 bit long literal has an upper case 'L' or lower case 'l' at the end. However, NEVER use the lower case 'l' because it is easily confused with a digit '1'.


The last two examples use lower case 'l' and are very confusing.

(The author once spent several hours debugging a program where this was the problem.)


Is the following an integer literal?