< Previous | Contents | Next >

Understanding Which Types to

Use

You have many choices when it comes to the fundamental types. So how do you know which type to use? Well, if you need an integer type, youre probably best off using int. Thats because int is generally implemented so that it occupies an amount of memory that is most efficiently handled by the computer. If you need to represent integer values greater than the maximum int or values that will never be negative, feel free to use an unsigned int.

If youre tight on memory, you can use a type that requires less storage. However, on most computers, memory shouldnt be much of an issue. (Pro- gramming on game consoles or mobile devices is another story.)

Finally, if you need a floating point number, youre probably best off using float, which again is likely to be implemented so that it occupies an amount of memory that is most efficiently handled by the computer.