Whats the point of so many data types? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Whats the point of so many data types?

why do we need so many different data types like int, float, double etc AND modifiers like short long etc? can't we have just one that does all the work?

29th Jul 2017, 10:57 AM
S V Shanmugha Balan
S V Shanmugha Balan - avatar
3 Answers
+ 15
Data types are required so that you know what "kind" of data your variable holds, or can hold. If you (and compiler, and runtime) know this information in advance, you can save a hell lot of runtime issues at compile time only, and also for utilizing the minimum memory space.
29th Jul 2017, 12:07 PM
Jihad Naji
Jihad Naji - avatar
+ 3
thank you!
31st Jul 2017, 1:51 PM
S V Shanmugha Balan
S V Shanmugha Balan - avatar
+ 1
By the time c and c++ were created, computers weren't that powerful enough to always use the biggest datatypes. You had to choose the datatype wisely to save ram, make your computer working faster and so on. Today you can choose almost freely what datatype you prefer. As long as the problem you're solving is no big deal, a complex game or you are working with a very limited micro controller. I'm, for example, using int for numbers most of time:)
29th Jul 2017, 8:48 PM
Theresa Leighfy
Theresa Leighfy - avatar