In C++ (which i am learning and am still very very new to), I have noticed that almost everybody uses the int
data type. But why? I know that short
, long
, and long long
have definite sizes pretty much, but int
seems like it might be short
or long
depending on the system. So, why don't people be more specific about the types? If they put a number into an int
that is too big for a short
, then on certain systems it will be really bad. If the number you're putting into an int
is small enough to fit into a short
, then on systems where it defaults to long
memory space is wasted. So why does everybody use int
?
According to the standard (C++11, §3.9.1/2),
Plain
int
s have the natural size suggested by the architecture of the execution environment; the other signed integer types are provided to meet special needs.
So int
is the type you should use unless you have a good reason to use any other type, because int
is supposed to map to the type that the architecture is optimized to use most of the time.