[Courses] [C Programming] Anyone still here?
Jenn Vesperman
jenn at anthill.echidna.id.au
Sat May 25 00:20:12 EST 2002
On Fri, 2002-05-24 at 23:39, Charlotte Oliver wrote:
> I know that it's the point where my head starts swimming.
> Maybe one of the instructor types could provide some
> guidance on the various types of variables and when to
> use them? Where the book fails in explanation here is
> in practicality. When do I have to worry about a long
> int vs an unsigned long int, etc.? I know the basic
> rules, but when do I have to worry about applying them
> in real life?
Ask questions. :)
With the math variable types:
A short is sometimes longer than an int, but never longer than a long.
An int is the width of the data bus.
A long is as many bytes as the CPU registers can handle in a single
operation.
Note that these lengths are NOT guaranteed. Fun, huh?
In practice:
A short is 16 or 32 bits
An int is 32 bits
A long is 32 bits (and rarely used)
A double is often 32 bits, as well
A float is 16 bits, but because within the 16 bits is the exponent, it
usually only has about five places of precision.
To use them:
Use an int for most math, an unsigned int if you want more than 31 bits
of precision and aren't using negative numbers.
Use a float if you need decimals or exponents.
Don't bother with the rest until you discover that you've run out of
room somewhere.
Ints are almost always the fastest thing to load, save and manipulate,
anyway.
Jenn V.
--
"Do you ever wonder if there's a whole section of geek culture
you miss out on by being a geek?" - Dancer.
jenn at anthill.echidna.id.au http://anthill.echidna.id.au/~jenn/
More information about the Courses
mailing list