Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable types

Status
Not open for further replies.

Denster

Programmer
Apr 9, 2001
198
GB
Just going to take my exams on the subject and could do with a bit of help on variable types.
in particular, whats the difference between double and float ?. what is "long" used for ?. Unsigned I believe is for '+' values, but what is "unsigned char"?. I cant understand why there are so many variations, any help on this subject would be greatly appreciated.
 
A double generally has greater precision than float, though this is not necessarily so. A float is guaranteed to have at least 6 decimal digits of precisionand a double is guaranteed to have at least 10 decimal digits of precision.

long is used when you need to handle a big number :) ... long and int may actually be the same size on a given implementation. But a long is guaranteed to be at least 32 bits in width, while an int is only guaranteed to be 16 bits.

The unsigned type specifier is for when you are dealing with values that will only be positive. In the case of unsigned char, this is a good data type for storing binary data, where the byte values could be greater than 127 (maximum value for a signed char). Also, note that the expression:

char foo;

foo could be either signed or unsigned. This is totally dependent on the implementation. So, if you need a char to be a signed char, you should specify it as signed char.

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top