0

why need to use int? why not just float everything since float must containt and accept integer?

25th Sep 2016, 4:38 AM
Maximilian Yuen
Maximilian  Yuen - avatar
5 odpowiedzi
+ 4
Actually int and float both use 4 bytes, 32 bits each. The only simple type that uses 2 bytes, 16 bits, is short and ushort. However, doubles are 8 bytes, 64 bits and decimals are 16 bytes, 128 bits. So doubles and decimal use more memory than integers and floats, but floats do not use more memory than integers and vice versa. Since they require the same size in bits. Now if your whole number is in the -32768 to 32767 range, you can use short instead of int to save memory space. Same goes with ushort 0-65535 .   Also using a real data type no matter the memory size requires more time to calculate than an int. So if speed is the name of the game for your program and you use a real number data type when an int could be used. Your program is not living up to its true potiental, expecially if you are facing fierce competition. Another example is if you want the user to enter their age or house number. The user could accidently type that they are 33.2 years and 11 months old, which would make no sense, or that they live at 45.37 street. It opens up the possibility for errors that would not happen when using int. There are many more reasons why you would not want to do this. Such as int holds a vastly larger integer value range (roughly -2 billion to 2 billion), compared to float. So if you wanted to use large whole numbers, using float would not work. I could go on and on, but basically int is used for whole numbers (within their intended value range) and you just got to deal with it.
27th Sep 2016, 1:44 AM
Alex Wiggins
Alex Wiggins - avatar
0
with int (integer) u only can use numbers like 3, 6 , 241 etc. with float u can use 3.56 or 37.06
12th Oct 2016, 3:08 PM
bernhard
- 1
In order to save memory we need to use int because when we declare variable of int data type it occupy 2 byte while when we decare it as float it occupy 4 byte .
25th Sep 2016, 8:15 AM
Pranav Dixit
Pranav Dixit - avatar
- 2
both the data type occupies same memory. but use of each data type is different for different scenario. Such as you can't allow user to input their age in 11.9 or street no as 16.2 etc in such scenario use of float is not appropriate also while defining temperature or percentage we need exact decimal because it affect the whole number so here we should not use int.
29th Sep 2016, 9:46 AM
Amey Chitale
Amey Chitale - avatar
- 5
U just need to accept it for what it is. High level programming is magic
26th Sep 2016, 1:17 AM
Nicholas
Nicholas - avatar