+ 1

What are the differences between different types of a category (in C++)?

I find it difficult to know what the uses of different types of category are... integer has 'short', 'int', 'long', 'long long', same with floating point. I'd be grateful if someone can help me about this.

13th Jan 2018, 9:56 AM
Rodo Anh
Rodo Anh - avatar
4 odpowiedzi
13th Jan 2018, 10:16 AM
Abhivarshini Maddala
Abhivarshini Maddala - avatar
+ 2
Well, the most important difference is the usage of memory. Integer types: byte, short, int, long Floating types: float, double that order goes from lowest to greatest memory. In world programming there's a non-written rule: make programs efficcent with minium of resources while possible. Example: if you need an input for an age of million of people. The average of ages is maxium 100 (Let's suppose). So if you have to do it, you should use short as data type, (even byte) for 2 reasons. 1) It's an integer data type, there are not ages with decimals, they're absolute. 2) Usage of memory. For million of data, memory is really important, while less memory, much better. Example: You need to save million of prices of products. You should use float as type. And the reasons are the same. Memory but as floating type, prices usually have decimals, so that's it. Another example, if you had to calculate numbers really big like distance from a galaxy to another, you should use long or double, it depends of you hehe. If you have another doubt Tell me. Greetings :D
13th Jan 2018, 5:35 PM
jaaxdev
jaaxdev - avatar
+ 1
@Rodo Anh Reduction of code (x+=1 instead of x = x+1, things like this xD) Recursion In java using threads is really useful Using data types as I explained Declare only variables that you need When you have too many lines of code, you have to consider those points, maybe not all, but some of them, yes.
13th Jan 2018, 6:10 PM
jaaxdev
jaaxdev - avatar
0
@Jaaziel Isai Well, there's 1 thing. About "making programs effecient with minimum of resources while possible". How can we know it is possible or not ?
13th Jan 2018, 6:01 PM
Rodo Anh
Rodo Anh - avatar