In which cases should we use int,float, double,long...? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

In which cases should we use int,float, double,long...?

29th Dec 2021, 1:17 AM
Tejaswini Adusumalli
2 Answers
+ 2
It depends on the size of the value you need. Also precision for floats and doubles. In the language of your choice run a sizeof on each data type to see how may bytes each can handle. 8 bits to a byte each bit is equal to 2^n where n is the index of the bit. You can calculate the max number available for that data type. For signed numbers (ie negative and positive values) one of the bits is used as a FLAG to indicate negative or positive value, hence the scope of minimum and maximum values change. Some items require a certain number of bits like address locations so you have to know what data type can fit that data. This link explains it better and gives a table so you can see the byte sizes and value scope. https://discover.hubpages.com/technology/Data-Types-in-C-Language *Other languages have different bit sizes for their data types.
29th Dec 2021, 1:34 AM
William Owens
William Owens - avatar
+ 1
In which language?!
29th Dec 2021, 1:19 AM
Dino Wun (Use the search bar plz!)
Dino Wun (Use the search bar plz!) - avatar