Size of enum type

Definition of the “enum” type:

An enumeration is a distinct type whose value is restricted to a range of values (see below for details), which may include several explicitly named constants (“enumerators“). The values of the constants are values of an integral type known as the underlying type of the enumeration.

CppReference.com

Size of the enum type

If you have read carefully the definition of the enum type, then it should be easy for you to provide the correct answer to the following problem:

#include <iostream>

enum foo
{
    typeA = 0,
    typeB,
    typeC
};

enum bar : typename uint64_t
{
    typeD = 0,
    typeE,
    typeF

};

int main()
{
    std::cout << "Size of <foo> type variable: " << sizeof(foo) << " bytes" << std::endl;
    std::cout << "Size of <bar> type variable: " << sizeof(bar) << " bytes" << std::endl;

    return 0;
}

Which is the calculated size of the enum type?

Please, find the correct answer below:


Unlock now all the premium content in this page.

Sign-in or register to buy access to this content using your virtual coins.


 

HappyHalloween

Get a spooky 10% off on my digital downloads


No tricks, all treats from us this Halloween.

Get up to 10% off on all digital downloads using the code "HALLO2022". Sale ends October 31st.

Follow PietroDigitalArt Etsy shop to not miss my next products.

Happy Halloween 2022 Join PietroLC.com – Talented developers’ community