Determining the Sizes of the Fundamental Types, a Built-In Array and a Pointer

Figure 8.14 uses sizeof to calculate the number of bytes used to store many of the standard data types. The output was produced using the default settings in Visual C++ 2012 on a Windows 7 computer. Type sizes are platform dependent. On another system, for example, double and long double may be of different sizes.

 1   // Fig. 8.14: fig08_14.cpp 2   // sizeof operator used to determine standard data type sizes. 3   #include <iostream> 4   using namespace std; 5  6   int main() 7   { 8      char c; // variable of type char 9      short s; // variable of type short10      int i; // variable of type int11      long l; // variable of type ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.