In addition to the primitive types previously discussed, there are
also the following: short int, long int, double,
signed char, unsigned char, signed short int,
unsigned short int, signed int, unsigned int,
signed long int, and unsigned long int.
The short and long type specifiers allow you more
control over the sized of your integers. short ints are guaranteed
to hold values from -32767 to +32767. ints are guarantted to hold
anything a short int can. long ints are guaranteed to
hold values from -2147483647 to +2147483647 as well as anything an int
can. The C compiler will let you write short for short int
and long for long int, but I won't.
A double is a floating-point type which is guaranteed to have
at least as many digits of precision and exponent as a float does.
Some compilers also allow the use of long doubles.
signed short int, signed int, and
signed long int are the same as short int, int,
and long int. unsigned types can hold only non-negative
values and thus gain you an extra bit of size: unsigned short ints
can hold values from 0 to at least 65536, etc.
unsigned chars can hold values between 0 and at least 256, and
signed chars can hold at least between -127 to 127. Unfortunately,
the ANSI C standard allows different C compilers to treat chars as
either signed or unsigned. Thus, if you expect to deal with the values of
characters not in the range of 0 to 127, you should define these characters as
either signed or unsigned.
Integer constants are assumed to be ints unless they don't
fit into an int, in which case they are assumed to be long
ints. Floating point constants are assumed to be doubles.
To declare an integer constant to be unsigned, append an u or
U to its end. To declare a constant to be long,
append an l or L. To declare a floating point constant
to be a float, append an f or F. For example,
174u, 835839283L, 3ul, 3.14159L, 1.00f.
I'm not sure if I've mentioned this before, but integer constants that
start with a 0 are interpreted in octal and integer constants that
start with a 0x are interpreted in hexadecimal. For example,
0777 is 511 and 0xFF is 255. C will even be stupid and
interpret 080 as 64, so be careful.
The following table will tell you what % fields to use when printing
or reading in different variable types from printf or scant:
Type Field Descriptor
--------------------------------------
float %f
double %lf
long double %Lf
char %c
short %hd
unsigned short %hu
int %d
unsigned int %u
long int %ld
unsigned long int %lu