I\'m looking for detailed information regarding the size of basic C++ types. I know that it depends on the architecture (16 bits, 32 bits, 64 bits) and the compiler.
I notice that all the other answers here have focused almost exclusively on integral types, while the questioner also asked about floating-points.
I don't think the C++ standard requires it, but compilers for the most common platforms these days generally follow the IEEE754 standard for their floating-point numbers. This standard specifies four types of binary floating-point (as well as some BCD formats, which I've never seen support for in C++ compilers):
How does this map onto C++ types, then? Generally the float
uses single precision; thus, sizeof(float) = 4
. Then double
uses double precision (I believe that's the source of the name double
), and long double
may be either double or quadruple precision (it's quadruple on my system, but on 32-bit systems it may be double). I don't know of any compilers that offer half precision floating-points.
In summary, this is the usual:
sizeof(float)
= 4sizeof(double)
= 8sizeof(long double)
= 8 or 16