0
can we use double in place of int or not?
int sum1 = 1000 / 5; //can we use double in place of int or not
3 Antworten
+ 2
Sudip Giri you can use double in place of int but you will not see much of a difference because 1000/5 is completely divisible and would return 200 as int and 200.0 as double.
Try double sum1 = 1000/6;
It will give you 166.0 and not the exact result because both the numbers are of type int, you atleast need to have one number of type double to get the exact answer.
double sum1 = 1000/6.0;
This will give 166.66... which is the exact result. Hope I'm clear.
+ 2
int cannot contain decimal point but double can be used to store a number which contains decimal point
0
Yes ofcourse but it take more memory
int takes 2 bits
float takes 8 bits