How To Choose Data Type In Program
Do you like this story?
When choosing the type to represent something in a program, think about the likely data range of the variable, for example if a variable is to hold student examination marks out of 100, then a int type will be more than sufficient, however if the variable is to hold, for example the population of US, then the integer type will be too small and a long unsigned int type will be required.
Unsigned variables are useful if we know in advance that there will never be a negative value for that variable, for example if we are considering number of students in a class then the value can never be less than zero so an unsigned variable may be used, any variable which is likely to contain decimal fractions will have to be a least a float, if we are considering a variable which is required to handle very large numbers i.e for program dealing with astronomy for example the long data type would be necessary to meet the accuracy requirements.
The char data type can hold numbers but is used to represent characters, a char can be assigned either a numeric value or the character 'A' are equivalent values for a char data type since 65 is the ASCII code for capital A.

This post was written by: Franklin Manuel
Franklin Manuel is a professional blogger, web designer and front end web developer. Follow him on Twitter
0 Responses to “How To Choose Data Type In Program”
Post a Comment