+ 1
What is the point of char? Or long and short... Or any of it.
Going through the data types and not sure why they have so many different types. Is it just to save space when writing a big program?
2 ответов
+ 4
When C was created, memory was tiny. The first system I compiled a C program on had 64K bytes. Therefore, making your data as small as possible was crucial to fit. Today's systems no longer need worry about it, but removing it from C++ would break many existing programs so it remains. I tend these days to use int because most of my numbers are under 100. The only time I use long is the few times my numbers require it.
0
Normally you also have different functionality for different types, so you can do different things with them.
If you += 1 an int of 2, it will be 3, if you do that with a char = 'c', it will be 'd'. Related, but not the same, right?
If you write 1+1 it becomes 2, if you write '1' + '1' it becomes "11".