Can I use double instead of float? As it is more easy. Will that affect grading?
I cannot speak for grading, perhaps someone else could answer that. Technically speaking, yes you can use a
double wherever you use a
float. While there may be no practical difference in the real world, there may be reasons why you might not want to do this:
- Generally the course teaches about choosing the right variable type for the task. For example, while you could store a
intit is generally discouraged. This probably carries over to other types as well. I imagine the instructors would be looking to see that you understand the differences between the types. In the auto-graded assignments this may not be an issue.
doubletype uses twice the amount of memory as a
float, and usually also takes slightly longer for the CPU to process compared to a
float. These differences are really tiny, and only noticeable when you have many variables or are performing many calculations. Again, I expect the instructors would be looking to see that you understand this added cost, and use the simplest type to perform the task.
- You might not necessarily be gaining anything by using a
double. If you can trace the source of the value in the variable, it may be coming from a
floatany way. Assigning a
doubledoes not gain any precision, as the information is not there to begin with.
Lastly, there may be times when you do actually need to use a
double, in which case a
float would be a mistake. A programmer needs to understand when this difference is important and choose the correct variable type.
I personally have not seen any occasion in the course which would benefit from either the magnitude or precision gained by using a
double, but I may be mistaken.
Can I use double instead of float?
Yes, you can!
As it is more easy
Well, this has nothing to do with easiness. A
double has double the precision and the size as a
double has a size of 8 bytes and can have up to ~15 digits after the decimal point while a
float has a size of 4 bytes and can have up to ~7 digits.
Will that affect grading?
No, it won't!