28 Chapter 4 Variables, Data Types, and Arithmetic Expressions
Type Specifiers:long,long long,short,unsigned, and
signed
If the specifierlongis placed directly before the intdeclaration, the declared integer
variable is of extended range on some computer systems. An example of a long int
declaration might be
long int factorial;
This declares the variable factorialto be a longinteger variable. As with floats and
doubles, the particular accuracy of a longvariable depends on your particular computer
system. On many systems, an intand a long intboth have the same range and either
can be used to store integer values up to 32-bits wide ( 231 – 1, or 2,147,483,647).
A constant value of type long intis formed by optionally appending the letter L
(upper- or lowercase) onto the end of an integer constant. No spaces are permitted
between the number and the L.So, the declaration
long int numberOfPoints = 131071100L;
declares the variable numberOfPoints to be of type long intwith an initial value of
131,071,100.
To display the value of a long intusing printf, the letter lis used as a modifier
before the integer format characters i,o,and x.This means that the format characters
%lican be used to display the value of a long intin decimal format, the characters %lo
can display the value in octal format, and the characters %lxcan display the value in
hexadecimal format.
There is also a long longinteger data type, so
long long int maxAllowedStorage;
declares the indicated variable to be of the specified extended range, which is guaranteed
to be at least 64 bits wide. Instead of a single letter l, two ls are used in the printfstring
to display long longintegers, as in %lli.
The longspecifier is also allowed in front of a doubledeclaration, as follows:
long double US_deficit_2004;
A long doubleconstant is written as a floating constant with the letter lor Limmedi-
ately following, such as
1.234e+7L
To display a long double,the Lmodifier is used. So,%Lfdisplays a long doublevalue
in floating-point notation,%Ledisplays the same value in scientific notation, and %Lgtells
printfto choose between %Lfand %Le.
The specifier short, when placed in front of the intdeclaration, tells the C compiler
that the particular variable being declared is used to store fairly small integer values.The
motivation for using shortvariables is primarily one of conserving memory space,
which can be an issue in situations in which the program needs a lot of memory and the
amount of available memory is limited.