0
Why don't we just use double instead of int
isn't double better for storing any kind of numerical data, so why do we use int?
3 odpowiedzi
+ 3
double uses more space, which probably isn't a huge concern nowadays. Still, sometimes it's useful to make it clear that the intended value is an integer and will not have a decimal part
+ 5
Also, apart from memory allocation size, whole number arithmetic operations are faster than floating points arithmetic operations. Plus, there are places where floating points usage doesn't make sense, for example, when we refer to an element's index in an array, or when we iterate in loops, using floating point types for loop iterator will cause problem, because iterator value isn't precise.
0
Dan Walker thanks