Next: September 20
Up: September lecture summary
Previous: Pointers
September 18
C has a rather small set of data types:
- int represents integers, with the ``natural'' precision
for the platform you're on (typically, but not necessarily 32 bits
these days). More or less precision can be specified using the
modifiers short or long. You may also specify
unsigned, whereas signed is the default. A literal
such as 4321 is an int, if you append an L
(e.g. 4321L it is a long int. The suffix U
indicates unsigned. A leading 0 indicates an octal (base 8) integer,
a leading 0x or 0X indicates a hexadecimal (base 16) integer.
- char is a single byte, representing a single character
in the local character set. These may be signed or
unsigned. A character literal is delimited by single
quotes (e.g. 'x'). Certain characters can be represented
by an escape sequence, e.g.
\n
for newline, \t
for
tab. chars are actually small integers, and can
participate in integer arithmetic.
- double represents a number with a fractional part with
double precision (how much precision is, again, machine-dependent).
More precision may be specified with long, less by using
type float. Include a decimal point (e.g. 123.4)
or an exponent (e.g. 1e-2) to indicate double, add the
suffix F to indicate float
How much precision? This is specified in the header
<float.h> for the particular machine you are on.
Variables are declared before use. The declaration statement may
include initialization:
int i, num, k= 3;
char a= 'T', *cp;
int *ip= &k;
num= k+3;
cp= &a;
A declaration may have the prefix const, which which case
warnings (may) occur if there is an attempt to change its value after
it is initialized.
Next: September 20
Up: September lecture summary
Previous: Pointers
Danny Heap
2002-12-16