sizeof a class : sizeof « Operators statements « C++ Tutorial






/* The following code example is taken from the book
 * "C++ Templates - The Complete Guide"
 * by David Vandevoorde and Nicolai M. Josuttis, Addison-Wesley, 2002
 *
 * (C) Copyright David Vandevoorde and Nicolai M. Josuttis 2002.
 * Permission to copy, use, modify, sell and distribute this software
 * is granted provided this copyright notice appears in all copies.
 * This software is provided "as is" without express or implied
 * warranty, and with no claim as to its suitability for any purpose.
 */
#include <iostream>

class EmptyClass {
};

int main()
{
    std::cout << "sizeof(EmptyClass): " << sizeof(EmptyClass)
              << '\n';
}
sizeof(EmptyClass): 1








3.6.sizeof
3.6.1.Demonstrate sizeof.
3.6.2.sizeof a union
3.6.3.sizeof a class
3.6.4.Object sizes
3.6.5.Using the sizeof operator for base class and derived class
3.6.6.Use sizeof operator on an array name: returns the number of bytes in the array