can I declare all variables as double?
Since the datatype "double" has the greatest range of values of the C++ data types..?
well, yeah. but to get the most efficient and compact code, you try to use the smallest you can. it also saves on RAM space.
for instance, if you are going to do a for loop and only need to do it 10 times, why use a double? I would consider it sloppy coding.
Reply:double can only be used for numerical values. There is nothing stopping you from using double for all numeric values. However double, when used in calculations may suffer in terms of using numbers with many digits after its decimal point e.g. 345.32432483243294873 . A float would be more appropriate for numbers such as this.
Reply:why not go all out and use a long double?
Tip: use the smallest type you need to do the job.
Your program will run faster and be - well - more esthetically pleasing.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment